1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  3. All Unity Pro perpetual license customers: your special offer to subscribe is ready! Click here.
    Dismiss Notice
  4. Unity 5.5 is now released.
    Dismiss Notice
  5. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  6. Unity 5.6 beta is now available for download.
    Dismiss Notice
  7. Get prepared for the Tizen Mobile App Incentive Program! Read more about the upcoming program here.
    Dismiss Notice
  8. Enter the Microsoft Developer Challenge for a chance to win prizes. Read more about it here.
    Dismiss Notice

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.