Search Unity

Debug Button Confusion

Discussion in 'Scripting' started by ColeChittim, Apr 27, 2013.

  1. ColeChittim

    ColeChittim

    Joined:
    Aug 11, 2011
    Posts:
    59
    So I have this code I attached to a camera trying to make a pause menu of sorts but when I clicked the button timescale wouldn't be set back 1 so I debugged and still can't get it to work. I feel like its something simple staring at me in the face. Basically the problem is the button doesn't pick up being clicked
    Code (csharp):
    1. function Update () {
    2.  
    3. //pause the game
    4.  
    5.         if(Input.GetKeyDown(KeyCode.Escape)  paused == false){
    6.                 paused = true;
    7.                 Time.timeScale = 0;
    8.         }
    9. }
    10.  
    11. function OnGUI () {
    12.  
    13. //display menu if paused
    14.  
    15.         if(paused){
    16.                 if (GUI.Button(Rect(10,70,50,30),"Click"))
    17.             Debug.Log("Clicked the button with text");
    18.  
    19.         }
    20. }
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Does paused exist outside of Update?
     
  3. ColeChittim

    ColeChittim

    Joined:
    Aug 11, 2011
    Posts:
    59
    It's not used any other function I just made it for this part of the code. If thats what you mean
     
    Last edited: Apr 27, 2013
  4. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    It's very weird, I've just tried your code and it works fine (as you expect it to work). I guess you are accessing "paused" somewhere else or something else is wrong but not the script that you showed.
     
  5. ColeChittim

    ColeChittim

    Joined:
    Aug 11, 2011
    Posts:
    59
    Your right made a new scene worked fine. :confused: I guess I'll just have this be a whole other script. I had this squeezed in with just my mouse look camera script. Still not sure what interfered since it's not used anywhere else whatever its fine now. Edit: Just figured it out and feel so stupid :mad: I was using lock cursor to center so when I clicked the button the mouse went to the center before it activate the button. Well its sorted out now
     
    Last edited: Apr 27, 2013
  6. ColeChittim

    ColeChittim

    Joined:
    Aug 11, 2011
    Posts:
    59
    Thanks guys