How to modify a variable on some instances of a prefab in an array of instances?

In essence my question is: for an array of prefabbed game object instances how do I change a variable on a script attached to the prefab on only some of the instances at a time?

I have an array of prefabbed game object square instances that, together, act as the floor which a character can walk on. Every time the char moves he jumps to the next square. Some of these squares are available to be walked on, some are not. The player can trigger groups of the unavailable square instances to become walkable. This part works fine.

I am now trying to make it so that this change to available is only temporary. My plan is to attach a script to the square prefab with a variable. When a group changes to available the variable goes up 3 for that group. Every time the character moves the variable for all square instances goes down one. When it reaches zero on any instance that instance switches back to not available.

I think part of my difficulty lies in the fact that only some of the instances are changing at a time, which ones depend on other things so they do not change in consistent groups. I need to be able to add to the variable on only some of the instances in the array at a time, but I’m not sure how to go about doing it.

I’d like to put up the code, but I’m not sure how without a lot of extra that is necessary to the selection of the squares, but not this particular problem.

Thank you for any help.

Make the script that’s attached to the floor contain an ID for that tile. Set the ID of the tile, when you are instantiating those objects (e.g. if you’re using a loop for (i = 0; i < tileCount; i++) set the ID to that i value or something along these lines). Now, because those tiles have ID’s you can easily access them inside of the array. just by passing the ID of the tile.

Now, once you try and make the tiles available, get the ID’s of the tiles that you want to change, then loop through these ID’s (dunno, put them inside of another array?) and pass them to the tileArray and change the variables you want to change inside of them.

Then, once your player moves, start a loop, that would go through every single object in the tileArray and decrease that variable for availability by one.

You could have a script that would run continuously, to check if they’re available or not, but I’d suggest running a script that checks it only when you move, after the decrease happens.

I can write up a code example, and comment it out if you want to, but I suggest trying to implement it yourself.