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

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class enemyHealth : MonoBehaviour { public float enemyMaxHealth; public GameObject enemyDeathFX; public Slider enemySlider; public bool drops; public GameObject theDrops; float currentHealth; // Use this for initialization void Start () { currentHealth = enemyMaxHealth; enemySlider.maxValue = currentHealth; enemySlider.value = currentHealth; } // Update is called once per frame void Update () { } public void addDamage(float damage){ enemySlider.gameObject.SetActive (true); currentHealth -= damage; enemySlider.value = currentHealth; if (currentHealth <= 0) makeDead (); } void makeDead(){ Destroy (gameObject); Instantiate (enemyDeathFX, transform.position, transform.rotation); if (drops) Instantiate (theDrops, transform.position, transform.rotation); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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