Cannot apply indexing with [] to an expression of type `UnityEngine.UI.Toggle'

Hello,
I am a newbie, following one tuitorial and it works but mine doesn’t. Please give me some hint thx very much!

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Linq;

publicclassToggleTest:MonoBehaviour{

ToggleGrouptoggleGroupInstance;

publicTogglecurrentSelection{
get{returntoggleGroupInstance.ActiveToggles().FirstOrDefault();}
}
//Usethisfor initialization
voidStart(){
toggleGroupInstance=GetComponent();
Debug.Log(“FirstSelected”+currentSelection.name);

SelectToggle(2);
}

publicvoidSelectToggle(intid){
vartoggles=toggleGroupInstance.GetComponentInChildren();
toggles[id].isOn=true; //???
}
}

well from the code you are doing GetComponentInChildren not GetComponentsInChildren (notice the s on components).

1 Like

wow thx! I didn’t notice this. I will remember and take a note.