Crosshair help

How i make it so when i right click the crosshair goes away and when i let go from right click it comes back. Here crosshair script

var crosshairTexture : Texture2D;
var position : Rect;

function Start()
{
		position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
}

function OnGUI()
{
	GUI.DrawTexture(position, crosshairTexture);	
}

1 Answer

1
var crosshairTexture : Texture2D;
var position : Rect;
var rightClick : boolean = true;

function Start()
{
        position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
}

function Update()
{

  if(Input.GetMouseButtonDown(1))
  {
      rightClick = false;
  }
  if(Input.GetMouseButtonUp(1))
  {
      rightClick = true;
  }
}

function OnGUI()
{
if(rightClick){
    GUI.DrawTexture(position, crosshairTexture);    
}
}