Question by
marcell123455 · Feb 24, 2016 at 12:55 PM ·
scripting problemtrigger
enable/disable trigger component with finding objects in scene with tag
Hi Untiy Community, I want to make a script that finds all gameobjects with the same name in scene and want to enable a trigger component on all these objects.
the gameobjects i am searching for will be generated in the scene if the game starts
Thx for any anwer :)
Comment
Best Answer
Answer by Jason2014 · Feb 24, 2016 at 05:55 PM
I recommend you to use tags instead of name. This will be much easier to define. Here's a code:
#pragma strict
private var ObjectsWithSameName : GameObject [];
function Start ()
{
ObjectsWithSameName = GameObject.FindGameObjectsWithTag ("Tag");
for (var object in ObjectsWithSameName)
{
print (object.gameObject.name);
object.GetComponent.<BoxCollider> ().isTrigger = true;
}
}