- Home /
GUI.toggle always false
Hey guys I am new to unity and having a problem with a GUI.toggle. Basically all I want to do is check the value of the GUI.Toggle when I press a button. The problem im having is that the GUI.Toggle value is always false ? even when clicked ? Below is the code cheers to anyone who has insight into the problem
public class EditPersonalWorkoutScript : MonoBehaviour{
public bool checkValue;
void OnGUI()
{
checkValue = GUI.Toggle(new Rect(120, 260, 130, 20), checkValue,"");
}
void OnMouseUp(){
addTheExercises();
}
private void addTheExercises(){
print (checkValue);
}
}
Answer by aldonaletto · Apr 20, 2012 at 11:18 AM
You've declared the variable checkValue, but is toggling chestValue:
public bool checkValue;
void OnGUI() { chestValue = GUI.Toggle(new Rect(120, 260, 130, 20), chestValue,""); } NOTE: There's a missing left brace after MonoBehaviour:
public class EditPersonalWorkoutScript : MonoBehaviour { //<- this brace is missing
Is this a typo?
sorry them the two things you pointed out were typos I'll edit my question to fix these. But the GUI.Toggle is still returning a false value
Well, this should work, unless you're declaring another checkValue inside the function, what would make it a temporary variable and hide the public checkValue. Another thing: public variables appear in the Inspector, which has elephant memory and will always start the game with the value set in the Editor - but the variable should toggle normally at runtime.
Your answer
Follow this Question
Related Questions
UI button doesn't appear - c# 3 Answers
Multiple Cars not working 1 Answer
GUIText which corresponds with a GUIBox 1 Answer
C# Boolean Doesn't Change Value 1 Answer
Distribute terrain in zones 3 Answers