/* * Using the DamageScript class, when the enemy laser hits the player, its health will be reduced accordingly. When the * players health reaches zero, the player game object is destroyed. If a gameobject collides with our player ship, * that object will also be destroyed, like the laser. * * Null reference error here?? */ private void OnTriggerEnter2D(Collider2D collision) { DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>(); if (local_damageScript == false) { return; } field_int_playerHealth -= local_damageScript.GetFieldIntDamage(); field_dob_percentage = (field_int_playerHealth) / (field_dob_playerHealthCopy) * 100; //Debug.Log(field_dob_percentage); local_damageScript.Destroy(); triggerHitSound(); if (field_int_playerHealth <= 0) { FindObjectOfType <LevelLoadingScript>().LoadGameOverScreen(); Destroy(gameObject); triggerDeathAnimation(); triggerDeathSound(); } }
private void OnTriggerEnter2D(Collider2D collision) { DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>(); field_float_health -= local_damageScript.GetFieldIntDamage(); local_damageScript.Destroy(); if (field_float_health <= 0) { Destroy(gameObject); triggerDeathAnimation(); triggerDeathSound(); } }
private void OnTriggerEnter2D(Collider2D collision) { DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>(); field_float_health -= local_damageScript.GetFieldIntDamage(); local_damageScript.Destroy(); triggerHitSound(); if (gameObject.tag == "Endboss" && field_float_health <= 0) { FindObjectOfType <LevelLoadingScript>().LoadLevel2(); Destroy(gameObject); triggerDeathAnimation(); triggerDeathSound(); addScorePoints(); } if (field_float_health <= 0) { Destroy(gameObject); triggerDeathAnimation(); triggerDeathSound(); addScorePoints(); } }