This is a sample from my r-Zones, it will show you how i was able to recreate a Zone from scrap.
[DOUBLEPOST=1421525785][/DOUBLEPOST]I posted that because i just wanted to show coders or new coders how to create new game objects and transform it in anyway they want. Add TriggerHurt on boxes so people get damage when they get closer, or even to walls, , Add a Radiation Zone on a player, like a time bomb, and if players get too close to him they get radiated, etc.Code:local function newTriggerBase(x,y,z,radius) trigger = UnityEngine.Object.FindObjectsOfTypeAll(global.TriggerBase._type) -- Create a new gameobject, empty newgameobj = new( UnityEngine.GameObject._type , nil )-- Add it to a layer (here it's Trigger layer ... but there are many others for every game objects, best thing is to get the gameobject you want and see what layer it has so you can use it) THIS PART IS ABSOLUTELLY NECESSARY OR IT WILL NOT WORK newgameobj.layer = UnityEngine.LayerMask.NameToLayer("Trigger")-- Give the gameobject a new position, this will be the CENTER of the zone newpos = newgameobj:GetComponent(UnityEngine.Transform._type).position newpos.x = x newpos.y = y newpos.z = z newgameobj:GetComponent(UnityEngine.Transform._type).position = newpos-- Give it a name so it's easy to find newgameobj.name = "Zone Manager"-- Add a spherecollider component, as a zone needs a Radius newgameobj:AddComponent(UnityEngine.SphereCollider._type) newgameobj:GetComponent(UnityEngine.SphereCollider._type).radius = radius-- Activate the new object newgameobj:SetActive(true) -- Make the object have a TriggerBase (It's a RAW zone, on it's own it doesn't do anything exept adding and removing players from zones, but that's exactly what i want on r-Zones) newgameobj:AddComponent(global.TriggerBase._type)-- Give a layer to the object ... so ... this i have no idea how they choose layers, so what i just did is get the layer from another default TriggerBase newgameobj:GetComponent(global.TriggerBase._type).interestLayers = trigger[trigger.Length-1]:GetComponent(global.TriggerBase._type).interestLayers return newgameobj:GetComponent(global.TriggerBase._type) end
New GameObject and Add stuff to it
Discussion in 'Rust Development' started by Reneb, Jan 17, 2015.