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

NullReferenceException Error

$
0
0
Hey, I have a problem with my enemyHealth script. I googled the error and found something that i have to make a new instance of the object. Maybe with ' new Object() ' or something else but i cant fix it >.< using UnityEngine; using System.Collections; public class enemyHealth : MonoBehaviour { Animator anim; enemyMovement enemyMove; enemySendDamage enemySendDmg; public int currentHealth = 20; public int storedExp = 10; public float actualTime; public Transform enemySprite; // Use this for initialization void Start() { anim = enemySprite.GetComponent(); enemyMove = GetComponent(); enemySendDmg = GetComponent(); } // Update is called once per frame void Update() { } void applyDamage(int damage) { if (currentHealth > 0) { currentHealth -= damage; if (currentHealth < 0) { currentHealth = 0; } if (currentHealth == 0) { enemySendDmg.colObject.SendMessage("applyExp", storedExp); die(); } else { anim.SetTrigger("hit"); } } } void die() { enemyMove.enabled = false; anim.SetTrigger("hit"); anim.SetTrigger("die"); Destroy(gameObject,1.23f); } } This is the full error message : NullReferenceException: Object reference not set to an instance of an object enemyHealth.applyDamage (Int32 damage) (at Assets/Scripts/Enemy/enemyHealth.cs:42) UnityEngine.Component:SendMessage(String, Object, SendMessageOptions) charSendDamage:OnTriggerStay2D(Collider2D) (at Assets/Scripts/Character/charSendDamage.cs:42) Regards, LifeArtist

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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