// This will take out player health when player touches the spk void OnTriggerStay2D(Collider2D other) { LinkController controller = other.GetComponent <LinkController>(); if (controller != null) { controller.changeHealth(-1); } }
// This function damages the player if the player and enemy collide and damages the enemy if the enemy // and a projectile collide. // Code in this sectionm was taken from https://learn.unity.com/tutorial/world-interactions-damage-zones-and-enemies?courseId=5c5c1e08edbc2a5465c7ec01&projectId=5c6166dbedbc2a0021b1bc7c void OnCollisionEnter2D(Collision2D other) { LinkController player = other.gameObject.GetComponent <LinkController>(); Projectile projectile = other.gameObject.GetComponent <Projectile>(); if (player != null) { player.changeHealth(-1); } if (projectile != null) { health -= 1; if (health == 0) { Destroy(gameObject); // Destroys the instance if they run out of health. } } }