hi …
It is possible to detect the distance , using rycast system ?
i am using below code to shoot … and kill works, but i need to obtain the distance
on a sniper game, to show the player the distance…
it isposible ?
thanks
here is the code I use.
var Effects: GameObject;
var TheDamage = 100;
function Update () {
var hit : RaycastHit ;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast (ray,hit,100))
{
var particleClone = Instantiate (Effects, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
Debug.DrawLine (ray.origin, hit.point);
}
}
}