Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    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
    Posts:
    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.