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

Can someone change this script to toggle?

Discussion in 'Scripting' started by Treasureman, Nov 19, 2014.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    Hey
    I,m having trouble changing this script to a toggle instead of holding the input down. Can someone write this for me?

    Here,s the script:
    Code (JavaScript):
    1. var aimTexture : GUITexture;
    2. function Update() {
    3.     // Only enable aim texture when 'SwitchWeapons' button is not pressed.
    4.     // In this case I have used 'Shift' key for this.
    5.     if (Input.GetButton("SwitchWeapons"))
    6.         aimTexture.enabled = true;
    7.     else
    8.         aimTexture.enabled = false;
    9. }
    Sorry for the trouble, but I just started with scripting.
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I'm not quite sure if that's exactly what you want, but i assume you meant something like:

    Code (JavaScript):
    1. var aimTexture : GUITexture;
    2. function Update() {
    3.     if (Input.GetButtonDown("SwitchWeapons"))
    4.         aimTexture.enabled = !aimTexture.enabled;
    5. }
    You could also use the 'GetButtonUp' version, that's up to your desire.