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

NullReferenceException by detecting health

$
0
0
Hello everyone, I'm working on a fps zombie game, currently I'm writing the code for the AI of the zombies. My AI use a detection for don't attacking a player already dead, for detect this I use this line of code : if (CurrentHealth > 0 && PlayerHealth.CurrentHealth > 0) { anim.SetBool ("IsIdle", false); nav.SetDestination (player.position); nav.speed = ZombieSpeed; } "CurrentHealth" is the current health of my zombie and "PlayerHealth.CurrentHealth" is the current health of the player. So i want to detect if my zombie and my player have more than 0 health point to trigger the attack. Unity give me this error : "NullReferenceException: Object reference not set to an instance of an object" The problem seems to coming from the "if(......)", but I don't know what I'm doing wrong, all works perfectly except this. So this piece of code is not correct ? Where is my mistake(s) ? I looked at different websites/forum, but I've don't found a solution.

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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