Have to press Fire1 button twice to run if statement?

I’m trying to make something happen when my raycast hits a specific object at close range, the problem I’m having is that when I do, I have to press the “fire1” button twice before anything happens. The script is attached to the built in first person controller asset.

var hit3 : RaycastHit;
var Distance3 :float;

function Update () {

Distance3 = hit3.distance;	
		
		if (Input.GetButtonUp("Fire1") && Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit3) && hit3.collider.name == "BED>ELEC" && Distance3 < 3)
		{
			Debug.Log("SUCESS");	
		}
}

I’m very new to scripting and Unity in general, so I might be missing something obvious. Any help is greatly appreciated! :slight_smile:

You are setting Distance3 to hit3.distance, but hit3.distance is not computed until the firstRaycast