Hi I’m quite new to coding and am trying to learn javascript, however I’m stuck on a particular issue:/
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs)
Aidamage.Update () (at Assets/Scripts/Part 2 - Survival GUI/Aidamage.js:19)
Basically my game is a survival game, and I’m trying to allow my character to damage my npc, here is my code:
var health = 20;
var newhealth;
var damage = 5;
var wait_time = 2;
var lock = 0;
var rayLength = 10;
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
playerAnim = GameObject.Find(“FPSArms_Axe@Idle”).GetComponent(PlayerControl);
if(hit.collider.gameObject.tag == “enemy” & Input.GetButtonDown(“Fire1”) & playerAnim.canSwing == true) {
newhealth -= 5;
}
if(health == 0){
Destroy(GameObject);
}
}
}
Would anybody be able to help?