- Home /
nGUI how to deactivate UICheckbox by script?
Hi, I'm new to nGUI (2.7), I'll explain shortly what I'm doing: I'm using a UIButton with UICheckbox script attached to make it stay selected when pressed. Another button has the duty to disable this button selected returning it to its initial state. In order to do this I created a script but the checkbox button doesn't return to its initial state (the checkmark sprite still active) despite the value isChecked it return false, can someone help me? Below you can see the script that I used, thanks in advance!
public void checkboxInitialStyle (){
UICheckbox checkbox = GameObject.Find("PressedButton").GetComponent<UICheckbox>();
if (checkbox != null) {
checkbox.isChecked = false;
}
}
You have to disable the checkmark sprite also ;) the checkbox can be disabled but having the mark still visible!
Answer by vexe · Oct 02, 2013 at 11:37 PM
Are you sure it's getting in and changing the value? How about you put a log to make sure it's getting in and that's checkbox
isn't null
:
if (checkbox != null) {
checkbox.isChecked = false;
print ("I'm in");
}
If it's not in, this means it's null so change the way you're getting the value of checkbox
, why not just assign it from the inspector? It's better anyway than GameObject.Find
Else if it's in and it's still not changed, I suggest you debug, and follow the code inside NGUI and see how it behaves.
Hi, i already check this and it works but the checkbox checkmark sprite still active. I update nGUI to 3.0.1 version so the code now is a little different:
if (checkbox != null) {
checkbox.value = false;
Debug.Log("do it! " + checkbox.value);
}
you're missing something, I can't tell. Did you try to follow execution inside NGUI's code to see what's it doing?
Did you assign the CheckSprite
variable in your UICheckbox
that's attached to your button?
For what exactly? - the CheckSprite
is set via the inspector, or just myCb.checkSprite
I just created a button, attached a script to it that un-checks another checkbox, it worked (same code as yours). Can you tell me more about your setup?
Your answer
Follow this Question
Related Questions
Unity 4.6 UI - Trigger OnClick event via script 1 Answer
GUI button to NGUI button ? 1 Answer
Script button. 1 Answer
Error wth enabling disabling scripts. 1 Answer
GUILayout to NGUI 0 Answers