i made an animation of my weapon swinging and it was supposed to play whenever i click the mouse button.
now it said “NullReferenceException: Object reference not set to an instance of an object
MeleeSystem.Update () (at Assets/MeleeSystem.js:11)”
???
i named my weapon “Hammer”.
this is my code:
#pragma strict
var thedamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var Hammer : Transform;
function Update ()
{ if (Input.GetButtonDown("Fire1"));
{
Hammer.animation.Play("attack");
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", thedamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}