Quantcast
Viewing latest article 9
Browse Latest Browse All 49

Invincibility Power Up

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 latest article 9
Browse Latest Browse All 49

Trending Articles