Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Error when player trying to take damage from a hazard

$
0
0
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!

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>