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

Toggle gui visibility?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Treasureman, Nov 8, 2014.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    Hello
    I have a script that makes gui texture appear when an input is held, but I want it to toggle instead. How would I do this

    Here's the script:
    Code (JavaScript):
    1. var aimTexture : GUITexture;
    2. function Update() {
    3.     // Only enable aim texture when 'Aim' button is not pressed.
    4.     // In this case I have used 'Shift' key for this.
    5.     if (Input.GetButton("Aim") || Input.GetKey("Fire2"))
    6.         aimTexture.enabled = true;
    7.     else
    8.         aimTexture.enabled = false;
    9. }
     
  2. Helical

    Helical

    Joined:
    Mar 2, 2014
    Posts:
    50
    Well first off there is an answer hub for specific questions, you should use it.
    Try the .GetButtonDown() functions they only activate when you press the button down. GetButton() returns true if current button state is Down().

    So overall you would have something like this

    if( input.GetButtonDown("whatever"){
    aimTexture.enabled = !aimTexture.enabled;
    }