gameObjects disappear after a while when running the game
Hi I've been working on this project for a while and now I got this issue, I don't know how it happened but after running the game the enemies disappear just like and the only code I made to make them disappear is when their health reaches 0, otherwise, I don't know where the problem is so if you could please help me out how to fix it, I'd really appreciate it, cuz I'm feeling so desperate due to this error (not the first error I get but the worst so far).
here's the enemy's code just in case you needed to check it out:
public class EnemyHealth : MonoBehaviour {
public float maxHealth;
float currentHealth;
public Slider healthBar;
public GameObject deathEffect;
public GameObject virus;
public AudioClip deathClip;
// Use this for initialization
void Start () {
currentHealth = maxHealth;
healthBar.maxValue = maxHealth;
healthBar.value = currentHealth;
}
// Update is called once per frame
void Update () {
}
public void Damaged (float damage)
{
healthBar.gameObject.SetActive(true);
currentHealth -= damage;
healthBar.value = currentHealth;
if (currentHealth <= 0)
{
Die();
healthBar.gameObject.SetActive(false);
}
}
void Die()
{
Destroy(gameObject);
AudioSource.PlayClipAtPoint(deathClip, Camera.main.transform.position);
Instantiate(deathEffect, new Vector3(virus.transform.position.x,virus.transform.position.y,virus.transform.position.z), transform.rotation);
}
}
so if you please know if there's a solution for this problem tell me how to fix it :'(
Your answer
Follow this Question
Related Questions
identify arrayed game objects 2 Answers
Button on win? 2 Answers
How can I access to child objects variables from other C# script ? 0 Answers