This is my code for a raycast thats meant to display how far something is away from you when you click. but it doesnt change the “distance” vriable. can someone fix it for me? It also has another set of code but dont worry about it.
#pragma strict
var dmg : int = 50;
var distance : float = 1.0;
function update()
{
if (Input.GetButtonDown("Fire1"))
{
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit))
{
distance = hit.distance;
hit.transform.SendMessage("Applydmg", dmg, SendMessageOptions.DontRequireReceiver);
}
}