1. Submit bugs to enter our 5.4 Beta Sweepstakes. Read more about it here.
  2. Unity 5.4 public beta is now available for all users. Grab the build and visit the 5.4 beta forum.
  3. Missing a module? More about the new installer in 5.3 here.
  4. 4.7.1 released for Xcode 7.3 support. Thread here.

How to create a new menu window

Discussion in 'Extensions & OnGUI' started by vanesinha18a, Apr 13, 2012.

  1. vanesinha18a

    vanesinha18a

    Joined:
    Apr 11, 2012
    Messages:
    30
    Hello, unity will any expert can give me a hand? :cool:

    I want to bring up a window with a menu!
    I play it on the menu to appear, it appears, but if I touch it in the options window disappears ...
    How can I do this?

    Code (csharp):
    1.  
    2.         public Rect windowRect;
    3.     public GUISkin windowDicaSkin;
    4.    
    5.     public bool limao01 = false;
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.    
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.         if(Input.touchCount == 1){
    15.             Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
    16.             RaycastHit hit;
    17.             if(Physics.Raycast(ray, out hit)){
    18.                 if(hit.transform.tag == "SairDicas"){
    19.                     Application.LoadLevel(0);
    20.                 }
    21.             }  
    22.         }
    23.        
    24.     }
    25.    
    26.     void  Awake (){
    27.         windowRect = new Rect(Screen.width / 2 - 300, Screen.height / 2 - 250, 500, 500);
    28.     }
    29.    
    30.     void  WindowFunction ( int windowID  ){
    31.         if(windowID == 0)
    32.         {
    33.              GUILayout.TextArea("Segundo OMS, o Brasil produz diariamente 600g de lixo por pessoa.", 400);
    34.         }
    35.     }
    36.    
    37.     void OnGUI(){
    38.         if(Input.touchCount == 1){
    39.             Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
    40.             RaycastHit hit;
    41.             if(Physics.Raycast(ray, out hit)){
    42.                 if(hit.transform.tag == "limao01"){
    43.                     limao01 = true;
    44.                 }
    45.                 if(limao01){
    46.                     GUI.skin = windowDicaSkin;
    47.                     windowRect = GUI.Window(0, windowRect, WindowFunction, "", GUI.skin.GetStyle("window"));
    48.                 }
    49.             }  
    50.         }
    51.     }
    52.