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?

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…

mods[arrayPos - 1].GetComponent(IndividualMods).enabled = false;,@Harryliu
mods[arrayPos].GetComponent(IndividualMods).enabled = false;