How to set bool true for each script.

Hello, i’m trying to set a bool true from 1 script to 6 others. I have 1 main script that needs set the others bool to true. The main script is rocket launcher script and the others are rocket launcher particles, but i couldn’t make only 1 particles system so i had to make 6 of them and i put 1 script on them all, there is a bool in those 6 scripts that enables particle emision. So, how do i set 1 bool called emitParticles to true in 6 scripts at once from other script?

I dunno if any of this makes any sense :smile: I guess i have to do it with foreach loop but i don’t know how that works. Ff it’s possible to do, then please help, thank you!

are the scripts on the “6” all the same? are they children on the “1”?

if so you could use “GetComponentsInChildren()” to pull off all of them and then iterate over the returned array with a for loop setting the bool in turn for each

Umm, can’t i just use GameObject.FindGameObjectsWithTag(“Particles”); ? I just don’t know the foreach(){} part :smile:

GameObject[] myParticles = GameObject.FindGameObjectsWithTag("Particles");//returns an array of gameobjects tagged as Particles
//iterate to each gameobjects tagged "Particles"
foreach(var item in myParticles){
  item.GetComponent<MyParticleScript>().emitParticles = true;
}
// using for loop(an example)
//with for loop you can specify the step/ the increment value
for(int i = 0 i<3; i++){//will only enable 4 particles
  myParticles[i].GetComponent<MyParticleScript>().emitParticles = true;
}
1 Like

Thank you very much!