Hello All,
Im trying to figure out how to activate and deactivate a bunch of prefabs in a certain room when entered, My thought was to use a trigger that when entered would Activate a bunch of gameobjects I had in an array.
I have many rooms in this scene and this way I could have the objects and scripts attached to those objects only be active right before I enter the room. This way all of the objects in all of the rooms aren’t always running and rotating etc…
is there a solution to doing this below is a trigger script but I get an error because active is not a member of GameObject
so know I cant think of a way to do this? right now I have a lot of objects using if distance < something but this is slowing down the game because I have a lot of prefabs in each room which makes up the level.
Heres the script anyone have any thoughts?
var activeObjects : GameObject[];
function Start()
{
activeObjects.active = false;
}
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == "myrobot")
{
activeObjects.active = true;
}
}
function OnTriggerExit(other : Collider)
{
if(other.gameObject.tag == "myrobot")
{
activeObjects.active = false;
}
}
http://unity3d.com/support/documentation/ScriptReference/GameObject-active.html
gameObject.active wont work because then its not a valid type but it does use the active
I also found out .enabled is not a member of Unity.GameObject as well
I could manually put in (because this works)
var gameobject1 : GameObject;
var gameObject2: GameObject;
gameObject1.active = false;
gameObject2.active = false;
But then I would have a whole list of objects and i dont know how many will actually be in each room. So my question is how would I do this with an array of prefabs?