Why Isn't My Raycast Working?

I have a script that casts a ray down the center of the screen and it finds the distance of objects and other stuff, it worked fine yesterday, but today it isn’t finding distance and I assume it’s because it’s not even being cast in the first place. If anyone knows what is wrong I would really appreciate help.

#pragma strict

var Distance : int;
var Holding = false;

private var lineTransform : Vector3;
private var startTransform : Vector3;

function Update ()
{
	if (Input.GetButtonDown("Fire1"))
	{
			Path();
	}
}

function Path()
{

var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));

{
	if(Holding == false)
	{
		if (Physics.Raycast (ray, hit, 100))
		{
			Distance = hit.distance;
			
			if(hit.transform.tag == "PickUp")
			{
				hit.transform.parent = transform;
				hit.rigidbody.useGravity = false;
				Holding = true;
			
				lineTransform = hit.point;
		}
	}
	if(Holding == true)
	{
		if (Physics.Raycast (ray, hit, 100))
		{
			Distance = hit.distance;
			
			if(hit.transform.tag == "PickUp")
			{
				hit.transform.parent = null;
				hit.rigidbody.useGravity = true;
				Holding = false;
			
				lineTransform = hit.point;
			}
		}
	}
}
}
}

It could be that your camera is too far from the hittable area. Try to increase a ray distance in “Physics.Raycast (ray, hit, 100)” from 100 to 1000 for example.

You could also use “Debug.DrawRay” which is nice for Debugging since it Shows you your actual raycast in what ever Color you like.

I actually got it to work by just restarting and using the same script, so I don’t really know what was wrong, but now I can’t get it to set the objects parent to null, if anyone knows what’s wrong please tell me.