Raycasting not reseting to null

Hi,

Is there a way to reset the raycast after the object leaves the ray? I’m having a dilemma where I’m casting a ray 10 units forward with an object, if it hits that object is assigned as the ray hit, but I need the ray hit to be reset to false after that object leaves the ray.`

var dHit : RaycastHit;

	if(Physics.Raycast(transform.position,-Vector3.up, dHit, .55)) //raycasts a line downwards, checks if player is on ground
	{
		if(dHit.collider != null)//player is on ground, sets down state as 1 (for use with jumping)
		{
			dState = 1;
		}
		else
		{
			dState = 0;
		}

`

A raycast wont null, it’ll go false.

That’s why we can enter it as args to an if statement.

if(dHit.collider != null) won’t execute if Raycast is false, ofc.

just use the original if(Physics.Raycast…), you don’t need a null check. If the raycast isn’t hitting something, it’s false.

var dHit : RaycastHit;
 
if(Physics.Raycast(transform.position,-Vector3.up, dHit, .55)) //raycasts a line downwards, checks if player is on ground
{
dState = 1;
}
else
{
dState = 0;
}

this way it’s basically saying "if the raycast hits something, dstate = 1, otherwise dstate = 0.