Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

When enemy dies the script loses object reference.

$
0
0
So I'm working on a little FPS and right now I have one enemy. When I kill that enemy it says "Object reference not set to an instance of the object. This is the area of code that the error is highlighting: Vector3 firePointPos = new Vector3(firePoint.position.x, firePoint.position.y, firePoint.position.z); RaycastHit hit; Debug.DrawRay(firePointPos, transform.forward, Color.cyan); if (Physics.Raycast(firePointPos, transform.forward, out hit)) { Debug.Log(hit.collider.tag); } Enemy enemy = hit.collider.GetComponent(); if (enemy != null) { enemy.DamageEnemy(damage); Debug.Log("We hit " + hit.collider + " and did " + damage + " damage"); } }` More specifically it is highlighting this line: Enemy enemy = hit.collider.GetComponent();

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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