Quantcast
Channel: Questions in topic: "power up"
Viewing all articles
Browse latest Browse all 49

Invincibility Power Up

$
0
0
Hi guys, I am trying to create a invincibility powerup that lasts a few seconds I have the following code: private PlayerHealth healthScript; void Awake () { healthScript = transform.root.GetComponent(); } // Use this for initialization void OnCollisionEnter2D (Collision2D other) { if (other.gameObject.tag == "Player") { StartCoroutine(NoDamage()); GetComponent().enabled = false; GetComponent().enabled = false; } } IEnumerator NoDamage () { Debug.Log ("Health Disabled " + PlayerHealth.health); healthScript.enabled = false; yield return new WaitForSeconds(5); Debug.Log ("Health Enabled " + PlayerHealth.health); healthScript.enabled = true; //Destroy(gameObject); } and I receive an error saying "object reference not set to an instance of an object" on the line "healthScript.enabled = false;" This script is on the character. Why does it tell me the script doesn't exist? Am I doing it wrong? What other way can I go about it?

Viewing all articles
Browse latest Browse all 49

Trending Articles



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