NullReferenceException: Object reference not set to an instance of an object

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);
			}
		}
	}
}

It’s pretty clear from first sight . First thing first, make your (var Hammer : Transform) “Public” . As the variable is now public , you can see Hammer Variable in your inspector section. Drag and Drop your Hammer ( Corresponding GameObject ) to initialize it. That’s it .

Hope it helps

cheers :slight_smile: