private void PlayerTakeDamage(Collision collision) { if (collision.gameObject.GetComponent <DamageOnCollision>() != null) { var collisionType = collision.gameObject.GetComponent <DamageOnCollision>().damageImpact; var collisionDamage = player.GetDamageValues(collisionType); player.TakeDamage(collisionDamage); var currentHealth = player.GetCurrentHealth(trackHealth); if (currentHealth > Mathf.Epsilon) { state = State.Alive; audioSource.PlayOneShot(damageImpact); // On collision with any object, make sure player is still facing front (left to right) // and lock the Z-axis, so they are still moving along the gamepath astronaut.transform.eulerAngles = new Vector3(0, 0, 0); astronaut.transform.position = new Vector3(transform.position.x, transform.position.y, 0); } else { state = State.Dying; audioSource.Stop(); audioSource.PlayOneShot(death); deathParticles.Play(); Invoke("LoadFirstLevel", levelLoadDelay); } } }