Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to return value from gui window function?

Discussion in 'Immediate Mode GUI (IMGUI)' started by aubergine, Sep 30, 2010.

  1. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,864
    Code (csharp):
    1.     void MenuAreYouSure () {
    2.         windowRect = GUILayout.Window (0, windowRect, WindowAreYouSure, "Are You Sure?");
    3.     }
    4.    
    5.     void WindowAreYouSure (int windowId) {
    6.         if(GUILayout.Button ("YES")){
    7.             Application.Quit();
    8. //HOW TO RETURN SOMETHING FROM HERE TO THE ABOVE MENUAREYOUSURE() function?
    9.         }
    10.         if(GUILayout.Button ("NO")){
    11.             menuSelected = MenuMain;
    12.         }
    13.     }
    Ive the above code, and a lack of c# knowledge. My question is, how would i return a bool value for instance from the bottom window function to the above menu function?
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    if you want to share a boolean, just declare it outside the function:
    boolean myValue = false;
     
  3. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,864
    Sure thats an option, but id also like to know if theres an easy c# way of doing this.
     
  4. cj-currie

    cj-currie

    Joined:
    Nov 27, 2008
    Posts:
    301
    Well, Appels' version _is_ the easy way to do it.

    I want to bump this thread because I need to know what the title asks: How can you get a return value from the func parameter of GUI.Window? I want a static function that can define a window and return values. It's going to be a file browser called from multiple scripts.

    This needs to be a custom file browser implementation, so existing solutions won't work –*though I would love to see some source, if possible.