Change value to a variable in all GameObjects

I got an object called chest (Is a pirate chest). Its formed by 2 separated parts: the top and the bottom. I instantiate them like this:

chest = Instantiate(cofreMaderaTop,Vector3(1.07,-0.9,0),Quaternion.identity);
chest.transform.localScale = Vector3(0.4,0.4,0.4);	
chest = Instantiate(cofreMaderaBottom,Vector3(1.07,-0.9,0),Quaternion.identity);
chest.transform.localScale = Vector3(0.4,0.4,0.4);

I got 10x of this instantiations because I need 10 chests on the screen. Every top-part of the chest it has a script attached. In that script, I defined the variable “beenClicked” witch is a boolean.

I need to set all the beenClicked variables from the 10 chests to false. Any clue?

I’m presuming that there is some reason why you are not just setting it to false on construction and actually do need to access all of the chests at some time.

The easiest way is to create a static list of all of your objects and then do a for loop over them.

This is similar to my answer here Adding variables from all scripts - Questions & Answers - Unity Discussions

But I guess you will be wanting JS.

In the attached script do this

 import System.Collections.Generic;


 public static var all : List.<NameOfYourScript> = new List.<NameOfYourScript>();

 void OnEnable() {
void OnDisable() {

Then in your script that does the instantiation:

for(var c in NameOfYourScript.all) {
    c.beenClicked = false;