how to change the value of gui.toogle c#

I presumed this was going to be an easy task, but it has proved very annoying and I am at my wits end here. I have a GUI.toggle button which is declared in the onGUI() method all I want to do is return the bool value of the GUI.toggle to indicate if it is clicked or not. The problem I am getting is that the value of the GUI.toogle button never changes even if it is clicked ? Below is the code I have thanks to anyone who can help

public class checkValue : MonoBehaviour { 

            public Texture2D SubmitButton;
            public bool val;
            public bool values = true;

     void OnGUI() 
	{
	
		
        val = GUI.Toggle(new Rect(120, 260, 130, 20), val,"helo");
		if(val != values){
			
			val = false;
                       Debug.Log(val);
			
		}
		
		else if(val == values){
			
		val = true;	
               Debug.Log(val);
		}

}

}

Do you have accidentally have “Collapse” selected at the top of the Console window?

no… the only option selected is clear on play.

Seems to work fine for me, both the value of “Val” and the Debug log both show true and false at the correct time :confused:

Why the conditionals after the Toggle() statement? You don’t need to do any further assignments to val - the Toggle will handle that for you.