So I am following Brackeys tutorial on YouTube as I just started with Unity on Friday. I have a script which sends out a raycast to find an object and reports the distance. It should show the distance but it does not do that for me.
It is a first person game survival game by the way.
Here is my script (Js) :
#pragma strict
var Damage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheSystem : Transform;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
//Attack animation
animation.Play("AttackMace");
}
// if (WeaponMace.animation.isPlaying == false)
// {
// WeaponMace.animation.CrossFade("Idle");
// }
//
// if (Input.GetKey (KeyCode.LeftShift))
// {
// WeaponMace.animation.CrossFade("Sprint");
// }
//
// if (Input.GetKeyUp(KeyCode.LeftShift))
// {
// WeaponMace.animation.CrossFade("Idle");
// }
}
function AttackDamage ()
{
//Attack function
var hit : RaycastHit;
if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
}
I get no errors, I have assigned TheSystem variable to the camera too. I don’t understand the problem.
Thanks.