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;
}
}
}
}
}
}