Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why my rect not working

Discussion in 'Scripting' started by mika132, Sep 4, 2012.

  1. mika132

    mika132

    Joined:
    Sep 4, 2012
    Posts:
    1
    I don't are sure is this right place to ask, but i ask now. Why this not print anything? It stop game, but not any menu.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class pause : MonoBehaviour {
    5.     public GUISkin Myskin;
    6.    
    7.    
    8.     private Rect windowRect;
    9.     private Rect optionRect;
    10.     private bool pauseMenu = false;
    11.     private bool optionMenu = false;
    12.        
    13.     // Use this for initialization
    14.     void Start () {
    15.         windowRect = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200);
    16.         optionRect = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200);      
    17.    
    18.     }
    19.    
    20.     // Update is called once per frame
    21.     void Update () {
    22.         if (Input.GetKey(KeyCode.P)) {
    23.             pauseMenu=true;
    24.         }
    25.        
    26.         if (pauseMenu) {
    27.             Time.timeScale = 0;
    28.         } else {
    29.             Time.timeScale = 1;
    30.         }
    31.     }
    32.    
    33.     private void OnGui() {
    34.         if (pauseMenu) {
    35.             windowRect = GUI.Window(0, windowRect, windowFunc, "Pause");
    36.         }
    37.         if (optionMenu) {
    38.             optionRect = GUI.Window(0, optionRect, optionFunc, "Options");
    39.         }
    40.     }
    41.     private void windowFunc( int id) {
    42.         if (GUILayout.Button ("Resume")) {
    43.             pauseMenu = false;
    44.         }
    45.         if (GUILayout.Button("Options")) {
    46.             optionMenu = true;
    47.         }
    48.         if (GUILayout.Button ("Save")) {
    49.            
    50.         }
    51.         if (GUILayout.Button ("Quit")) {
    52.             Application.LoadLevel("window");
    53.         }
    54.     }
    55.    
    56.     private void optionFunc( int id ) {
    57.         if (GUILayout.Button ("Back")) {
    58.             optionMenu = false;
    59.         }
    60.     }
    61.    
    62. }
    63.  
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    It's OnGUI not OnGui. Also, don't make it private.