How to deactivate all GameObject in a array, except last one

RectTransform controls = x.GetComponentsInChildren();

				for (int i = 0; i < controls.Length-1 ; i++) {

  •  		}*

here is the code…
its working perfectly…
only problem is that it isnt activating last gameobject.
it is disabling all gameobjects & i dont want to disable last gameobject.

Just do this:

for (int i = 0; i < controls.Length ; i++) {
    controls*.gameObject.SetActive(i >= controls.Length-1);*

Of course we have to iterate through all objects if you want to enable or disable all of them. If you don’t iterate over one object, of course it won’t be affected at all. The key is to use a boolean expression for the active state. Since we want to disable all objects except the last one, the condition i >= controls.Length-1 is false for all “i” except for the last one where it is true.

“controls.Length-1” replace with this “controls.Length-2” .I hope it works for you

Int number = controls.length;
controls[number].gameObject.SetActive(true);,Int number = controls.length;

Int number = controls.length;