Search Unity

Scripting with C# with OnGUI and some questions

Discussion in 'Scripting' started by Khazzack, Nov 9, 2013.

  1. Khazzack

    Khazzack

    Joined:
    Sep 27, 2013
    Posts:
    29
    So, im creating a script for a project im working on.
    And basically i have a script that shows some GUI when i click the "menu button" in game,

    The gui shows some buttons. And when one of the GUI buttons is clicked, i want it to close down the GUI already up and load a new script which will show the GUI of my inventory for example...

    // Inventory
    if(GUI.Button(new Rect(Screen.width / 2 - 245,(Screen.height / 2) - 150,100,100), "Inventory"))
    {
    // Here is where i want it to load a new script / GUI from a different script
    }


    How would i go about doing this?

    Thanks in advance

    // edit, i already have a function to close the GUI from this script, so if i did the same on another script, would that work?

    Or if i did that, how would i go about calling the function on the other script to load the new script when the button is pressed in this script....

    Maybe that makes more sense?
     
    Last edited: Nov 9, 2013
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    You can use this.enabled = false; to stop the script you are in and get the other with GetComponent.