Hi guys,
I am currently working on a game that includes a health system. As part of the game, when the player runs into a saw they take damage, managed by an already set-up "modifyHealth" action. However, when the player collides with the saw, I instead get the error:
"NullReferenceException: Object reference not set to an instance of an object
SawBlade.OnTriggerEnter (UnityEngine.Collider c) (at Assets/Scripts/SawBlade.cs:14)"
Here is the code in question:
using UnityEngine;
using System.Collections;
public class SawBlade : MonoBehaviour {
public float speed = 300;
void Update () {
transform.Rotate (Vector3.forward * speed *Time.deltaTime, Space.World);
}
void OnTriggerEnter(Collider c) {
if (c.tag == "Player") {
c.GetComponent().modifyHealth(-10);
}
}
}
Does anyone know what could possibly be the problem?
Thanks!
↧