I’ve come up with an error saying : ‘NullReferenceException: Object not set to an instance of an object Weapon+$AttackDamage$20+$.MoveNext() (at Assets/SurvivalAssets/Scripts/Weapon.js:33’
#pragma strict
var TheDammage : int = 25;
var Distance : float;
var MaxDistance : float = 4.5;
var TheAnimator : Animator;
var DammageDelay : float = 0.6;
var TheSystem : Transform;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
AttackDammage();
}
}
function AttackDammage ()
{
TheAnimator.SetBool("Hit01", true);
TheAnimator.SetBool("Hit02", true);
}
yield WaitForSeconds(DammageDelay);
var hit : RaycastHit;
if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
TheAnimator.SetBool("Hit01", false);
TheAnimator.SetBool("Hit02", false);
}