How could i get all objects with a specific tag and then set a variable in a script they have?
Has both examples you want.
Sorry frazed what i said badly. How would I get a script each one of the objects with the specific tag.
ScriptName src = FoundObject.GetComponent();
Scripts Variable:)
src.PublicVarName
Ok im sorry i dont understand how that would go with what im saying. To find all objects with a specific tag then go into there script and change a variable or check it.
void Start
{
GameObject[] objs = GameObject.FindGameObjectsWithTag("Enemy");
foreach(GameObject g in objs)
{
CustomScript cs = g.GetComponent<CustomScript>();
cs.DoCustomVar = true;
}
}
I could’ve missed something but overall this should do.
It will throw an error if the object with that tag doesn’t have the script but I’ll leave error handling to you.
Could you make that javascript? Thanks
Please?
Ok i got this togethor but how do i check the variable using a static variable or an other way?(im trying to check if all humans have zero health)
function chek(){
target = GameObject.FindGameObjectsWithTag("human");
for(GameObject in target)
{
if(){
}
}
}
Do you want to try OnCollision enter to check the Game Object?
function OnTriggerEnter(Collider otherObject){
if(otherObject.tag == "human")
{
Do something you want;
}
}
No im trying to get every game object with the tag human and check there health value and if there all = 0 then do something.
function chek(){
target = GameObject.FindGameObjectsWithTag("human");
for(GameObject in target){
if(target.GetComponent(HumanNormalScript).actionpoints <= 0){
print("hey");
}
}
}