- Home /
Disable the previous variable?
I have a script that cycles through an array. When an item in an array is selected I enabled it:
mods[arrayPos].GetComponent(IndividualMods).enabled = true;
Now, when I select the next item in the line, how can I disable the previous one?
Answer by jgodfrey · Jun 14, 2016 at 02:10 AM
Depending on the details, you could do a number of things... The best might be to simply keep a reference to the currently selected item. Then when you're ready to select another item, disable the current reference, enable the new item, and store the new item as the currently selected one.
Otherwise, if there aren't very many items in the array (and you're not doing it very often (like, in every frame)), you could simply disable all items prior to enabling the item you're interested in...
Answer by bull777 · Jun 14, 2016 at 09:39 PM
mods[arrayPos - 1].GetComponent(IndividualMods).enabled = false;,@Harryliu mods[arrayPos].GetComponent(IndividualMods).enabled = false;
Your answer
Follow this Question
Related Questions
Toggle ON/OFF MaterialChange 0 Answers
Array bug or script error 1 Answer
Game won't run on iPhone even with the device selected 0 Answers
Sorting arrays? 1 Answer
Display Game Center photo in iOS game 0 Answers