Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted UI Reappear.

Discussion in 'Scripting' started by CodyProductions, Apr 22, 2021.

  1. CodyProductions

    CodyProductions

    Joined:
    Jun 11, 2019
    Posts:
    56
    Hello, I'm trying to have this UI Reappear.
    When you load in to the game it appears and when you click on it, it disappears but if the player want to open it again they can press on a trigger button.
    Now the thing is, the trigger button won't work!
    Here's the open and close script:
    Code (CSharp):
    1. // Start is called before the first frame update
    2.     void Start()
    3.     {
    4.         UiObject.SetActive(true);
    5.  
    6.     }
    7.     // Update is called once per frame
    8.     void Update()
    9.     {
    10.         if(Input.GetMouseButtonDown(0))
    11.         {
    12.             UiObject.SetActive(false);
    13.         }
    and here is the trigger button script:
    Code (CSharp):
    1.     // Start is called before the first frame update
    2.     void Start()
    3.     {
    4.  
    5.     }
    6.     // Update is called once per frame
    7.     void Update()
    8.     {
    9.        if(Input.GetMouseButtonDown(0))
    10.         {
    11.             UiObject.SetActive(true);
    12.         }
    13.     }
    14.    
    edit: (they are different scripts)
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    6,132
    - delete the second script unless you really need that for something else
    - make a function in the first script for example ToggleUIObject (I advise you to name it something more concrete, both the UIObject and the function name with it).
    - in that function toggle the UI like
    UiObject.setActive(!UiObject.activeSelf);

    - then you can add this game object / function to the button's OnClick event in the inspector
     
  3. CodyProductions

    CodyProductions

    Joined:
    Jun 11, 2019
    Posts:
    56
    The other button is to bring up the menu again and that's what I'm trying to do. this didn't work but thanks for at least responding, I'm just going to scrap this from the game
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    6,132
    Well... okay then...
     
    Joe-Censored likes this.
unityunity