- Home /
using arrays to perform multiple tasks
I am using a clunky system to make a UI button push turn off all instances of another UI element (infoCard)- I have all other instances of infoCard fadeOut and the one I want to fadeIn. This means I need to maintain animation controllers for fadeIn and fadeOut of each infoCard, this is obviously very unwieldy.
I want to use an array to check to see if any infoCard is on, fade it out and fade in the infoCard corresponding to the UI button pushed. Not sure where to start though, any pushes in the right direction would be appreciated.
Thanks!
Answer by Rikland · Aug 20, 2015 at 10:53 PM
Not sure I understand, but can't you create prefab of an infoCard that has a script that stores the state on/off in a bool variable. In Start or Awake the script could find all objects with this script and store in an array variable. The script could listen for clicks and when that happens it could iterate through the array and set the bool to false on all the instances, then set the bool on itself to true of course.
In update you could check if that bool is true or false and respectively increment or decrement a float variable that controls the visibility of the infoCard.
thanks for the suggestion, I will see if I can figure it out. So it would turn off the entire array (including the one corresponding to the click) and then turn the correct one back on, is that right? very helpful, thanks!
So it would turn off the entire array (including the one corresponding to the click) and then turn the correct one back on, is that right?
Yes, that is what I meant.
Your answer
![](https://koobas.hobune.stream/wayback/20220612000742im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity C# Highscore table 2 Answers
Help with for loop and arrays 3 Answers
Linear Interpolation of Array Values 1 Answer
Get all GameObjects by variable value 2 Answers
Problems with Arrays 2 Answers