Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Make gui appear when input is held?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Treasureman, Sep 29, 2014.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    Hey, I want a gui texture to appear when the input "Aim" is held down and another script so that gui will disappear when the aim input is held

    Here's my Aim script (JacaScript):

    var zoom : int = 20; //determines amount of zoom capable. Larger number means further zoomed in
    var normal : int = 60; //determines the default view of the camera when not zoomed in
    var smooth : float = 5; //smooth determines speed of transition between zoomed in and default state
    private var zoomedIn = false; //boolean that determines whether we are in zoomed in state or not
    //This function zooms capabilities with left mouse. If it's zoomed in, it will zoom out
    function Update()
    {
    zoomedIn = false;
    if( Input.GetButton("Aim") )
    {
    zoomedIn = true;
    }

    //If "zoomedIn" is true, then it will not zoom in, but if it's false (not zoomed in) then it will zoom in.
    if( zoomedIn == true )
    {
    camera.fieldOfView = Mathf.Lerp( camera.fieldOfView, zoom, Time.deltaTime*smooth );
    }
    else
    {
    camera.fieldOfView = Mathf.Lerp( camera.fieldOfView, normal, Time.deltaTime*smooth );
    }
    }