How could I find all objects with a tag. Then check a script they have on them and check if all there scritps have a variable and if that variable = 0?? Im trying to make a turn system. (Javascript Please)
Thanks.
var objects : GameObject[] = GameObject.FindGameObjectsWithTag ("tag");
for (var obj : GameObject in objects) {
var script : SomeScript = obj.GetComponent (SomeScript);
if (script != null script .someVar == 0) {
// All conditions have been met
}
}
Ok that works but it seems to only check one. Then do it i want if ALL are equlal to 0?
var objects : GameObject[] = GameObject.FindGameObjectsWithTag ("tag");
for (var obj : GameObject in objects) {
var doit = true;
if(! condition 1) doit = false;
if(! condition 2) doit = false;
if(! condition 3) doit = false;
if(doit){
// do something
}
}
There is an error in logic in this code.
If your script == null, then script.somevar will return an error. ![]()
Wait does that check for the variable in theone you gave me?
Short circuit evaluation should dump out of the conditional if the script is null. Unless this is a wonky US implementation. ![]()
I always love it when people PM me and don’t bother to ask in the forum so others can learn too.
In this case, I dont understand the question. You want to change criteria independently based on each model. Just add strings and test against the tags. or some other criteria. What I gave you was rudimentary.