- Home /
How to find all objects with an tag and change an value in all of them?
I have 7 separate objects on my scene with tag "Enemy" and what i want to do now is to change value "RaceBeginner" from false to true in script called "EnemyShipAI" on every object with tag "Enemy".
I found something like this but i have no idea how to use it to change those values:
GameObject.FindGameObjectsWithTag("EnemyAI").GetComponent("EnemyShipAI").RaceBeginnerEnemy = true;
Answer by Eric5h5 · Dec 29, 2011 at 03:34 PM
var enemies = GameObject.FindGameObjectsWithTag("EnemyAI");
for (enemy in enemies) enemy.GetComponent(EnemyShipAI).RaceBeginnerEnemy = true;
It's bad practice to use quotes with GetComponent. Also it would be easier if you follow the convention of using lowercase for variable names and uppercase for class and function names.
does not work, why? is this on javascript? or on c#? Im a begginer btw:P
Your answer
Follow this Question
Related Questions
Changing gameobject assigned to a variable from string 1 Answer
Changing GameObject texture? 4 Answers
Modifying a shader color dynamicly through another script 0 Answers
How do I change what player I want to controll when there is multiple players? 2 Answers
Change texture of GUItexture from script 4 Answers