Well I said it all in the title. I’m an absolute beginner to Unity and I’m following the Brackeys tutorial on youtube and no matter how high I set the max distance in the inspector tab or in the actual code it only takes damage when its a zero with decimals as I said.
Any help would be much, much appreciated.
Thanks
Here’s the Code for the player:
#pragma strict
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 20.0;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
And for the Enemy:
#pragma strict
var Health = 100;
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
}