- Home /
Question by
_Remu_ · May 31, 2015 at 08:24 AM ·
arrayaddcomponentfindgameobjectswithtagquackbce0138
AddComponent To GameObjects On Array
Hello, is it possible for me to add the component "TimeGate" to every object with the tag "PhysicsObject"?
Whenever I try, I get the error "(15,53): BCE0138: 'quack' is not a generic definition"
Here is the code:
var collisionObject : GameObject;
var physicsObjects : GameObject[];
function OnTriggerExit(collision : Collider)
{
collisionObject = collision.gameObject;
if(collisionObject.tag == "Player")
{
physicsObjects = GameObject.FindGameObjectsWithTag("PhysicsObject");
if(!collisionObject.GetComponent("TimeGate"))
{
collisionObject.AddComponent.<TimeGate>();
physicsObjects.AddComponent.<TimeGate>();
}
}
}
Comment
Answer by fafase · May 31, 2015 at 08:28 AM
PhysicsObject is an array so you need to iterate.
function OnTriggerExit(collision : Collider)
{
collisionObject = collision.gameObject;
if(collisionObject.tag == "Player")
{
physicsObjects = GameObject.FindGameObjectsWithTag("PhysicsObject");
if(!collisionObject.GetComponent("TimeGate")){
collisionObject.AddComponent.<TimeGate>();
for(var i :int = 0; i < physicsObject.Length; i++){
physicsObjects[i].AddComponent.<TimeGate>();
}
}
}
}