- Home /
Question by
Redamz · Jul 22, 2012 at 08:40 AM ·
gameobjectinstantiatecreateempty
Any way to create a gamobject only if there is an empty space?
Hi guys, I was wondering if it was possible to create objects (in game) only if there will be no interactions with other objects, aka an empty space. Any suggestion is welcome :)
Comment
Answer by xSpectrum · Jul 22, 2012 at 10:02 AM
The simple way to do this would be to make an empty game object with a sphere/box collider about the size, shape and position of the object you want to spawn (I'm guessing you want something to spawn similar to forge mode in Halo), child it to your player, set "isTrigger" to true, and then have a script attached to it with the following:
var canSpawn : boolean
function OnTriggerEnter(other : Collider)
{
canSpawn = false;
}
function OnTriggerEnter(other : Collider)
{
canSpawn = true;
}
Then just check if "canSpawn" is true when you want to spawn the object, then instantiate it.