This script controls the cameras FOV when “Fire2” is pressed as well as displaying a GUI texture. However, once the user presses the button once, the texture displays and does not disappear until the button is pressed again - I want it to only show when the button is held down?
using UnityEngine;
using System.Collections;
public class awpScopeIn : MonoBehaviour {
public Texture scopeGUI;
private bool _isScoped = false;
public Color color = Color.black;
private Camera cam;
public GameObject awp_graphics;
void Start()
{
cam = GetComponentInParent( typeof(Camera) ) as Camera;
cam.clearFlags = CameraClearFlags.SolidColor;
cam.fieldOfView = 70f;
}
void OnGUI()
{
float width = 600;
float height = 600;
if (_isScoped) {
GUI.DrawTexture (new Rect ((Screen.width / 2) - (width/2), (Screen.height / 2) - (height/2), width, height), scopeGUI);
}
}
void Update()
{
if(Input.GetButtonDown("Fire2"))
{
_isScoped = !_isScoped;
cam.backgroundColor = color;
cam.fieldOfView = 45f;
awp_graphics.gameObject.SetActive(false);
}else if(Input.GetButtonUp("Fire2"))
{
cam.fieldOfView = 70f;
awp_graphics.gameObject.SetActive(true);
}
}
}