- Home /
C# Boolean Doesn't Change Value
I have a script that changes the value of someBool depending on what mouse button was clicked and what value someBool has. But for some reason the value of someBool doesn't change. As far as I can tell these if statements should be valid. Any idea what is wrong with this script?
using UnityEngine;
using System.Collections;
public class SomeScript : MonoBehaviour {
public bool someBool;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void OnGUI () {
if (GUI.Button(new Rect(10, 70, 250, 30), "Click to Change someBool's value")){
if(Input.GetMouseButtonUp(0)){
if(someBool = false){
someBool = true;
}
else if(someBool = true){
someBool = false;
}
}
else if(Input.GetMouseButtonUp(1)){
if(someBool = true){
someBool = false;
}
else if(someBool = false){
someBool = true;
}
}
}
GUI.TextArea(new Rect(10, 50, 40, 20), someBool.ToString(), 200);
}
}
Answer by Eric5h5 · Oct 20, 2013 at 03:33 AM
You would get a warning about the usage of "=" rather than "==" if you used that script. Read the warning and do what it says.
Your answer
Follow this Question
Related Questions
How to dynamically change the text in Unity(Augmented Reality + NYARtoolkit(C#)) ? 0 Answers
C# How to Drag and Scale with Mouse Window 0 Answers
C# GUILayout.Box GUIContent 2 Answers
Unity editor works but the built game doesnt. 0 Answers
C# using a Horizontal Slider for Anistropic Filtering 1 Answer