Raycast Help

So, I’ve got this script which works well. It notices that I’ve clicked on the object in the world, using the screen space. However, in the console, it displays the print four or five times. Here’s the script, so basically, for some reason, it records the hit more than once per click of my fire2. Any help would be awesome, thanks!

var distance = 100;
var target : Camera;

function Update () 
{
	if (Input.GetButton("Fire2"))
	{
		var objectTrans = GetComponent(Transform);
		var ray : Ray = target.ScreenPointToRay (Input.mousePosition);
		var hit : RaycastHit;
		if (Physics.Raycast(ray, hit, distance))
		{
			if (hit.transform == objectTrans)
			{
				print ("Hit!");
			}
		}
	}
}

GetButton returns true every frame…use GetButtonDown instead.

–Eric

Awesome! Worked like a charm. Should’ve known. Thanks!