- Home /
4.6 .interactable not working
Can't seem to get this to work, I'm trying to make a button uninteractable when the level hasn't been unlocked yet. I based my code on the "working code" of someone else, don't understand why his code would work and mine doesn't.
GameObject myButton;
myButton = GameObject.Find ("Button");
myButton.GetComponent().interactable = false;
myButton.GetComponent().interactable = true;
I have "using UnityEngine.UI;" at top
void CheckLockedLevels (){
GameObject Button;
for(int j = 1; j < LockLevel.levels; j++){
levelIndex = (j+1);
if((PlayerPrefs.GetInt("level"+levelIndex.ToString()))==1){
Button = GameObject.Find("Level"+(j+1));
Button.GetComponent().interactable = false;
}
}
}
I'm getting an error i haven't seen before: the type arguments UnityEngine.GameObject.GetComponent()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Thanks in advance :)
Comment
Best Answer
Answer by Danor · Oct 27, 2014 at 06:56 PM
void CheckLockedLevels (){
for(int j = 1; j < LockLevel.levels; j++){
levelIndex = (j+1);
if((PlayerPrefs.GetInt("level"+levelIndex.ToString()))==1){
Button = GameObject.Find("Level"+(j+1));
Button.GetComponent<Button>().interactable = true;
}
if((PlayerPrefs.GetInt("level"+levelIndex.ToString()))==0){
Button = GameObject.Find("Level"+(j+1));
Button.GetComponent<Button>().interactable = false;
}
}
}
this code works :)
$$anonymous$$ey line from this is
button.GetComponent<Button>().interactable = false;