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

Enemy health and bullet problem

$
0
0
[Edit]: This script is attached to the enemy, by the way! Hello, I'm having a little trouble with my enemy health script. I asked a question similar to this one a while ago, but I'm using my newer script now, and can't figure out how to solve this problem. Here's the health script: var hit = 0; var bulletHit : AudioSource; var bullet : GameObject; function OnTriggerEnter(){ hit +=1; Update(); audio.Play(); } function Update(){ if(hit == 3){ Destroy(bullet.gameObject); Destroy(gameObject); } } It basically makes it so that if the bullet object enters the trigger on the enemy (Collider set to trigger) it adds a hit to it and if there are 3 hits, it destroys it. **The Problem**: The bullets don't get destroyed when they hit the enemy. They continue to travel for 5 seconds (because of the Timed Object Destructor.) I tried to use this, but it didn't work either: DestroyImmediate(bullet, true); and DestroyImmediate(bullet.gameObject, true); Can someone help me with this? Thanks.

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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