Lose health and respawn after falling

I’m making a 2d platformer and I’m looking for something like the Shantae games where instead of having lives the player to falls off cliffs and loses a heart after respawning to the stage. I have the game over and respawn system set, but the player ends up recovering lost health after the respawn as opposed to losing.

Please help!

My kill script: `using UnityEngine;
using System.Collections;

public class KillPlayer : MonoBehaviour {

public Player player;

// Use this for initialization
void Start () {
	player = FindObjectOfType<Player> ();

}

// Update is called once per frame
void Update () {


}

void OnTriggerEnter2D(Collider2D other) {
	if (other.tag == "Player") {
		player.Death ();
		player.Damage (1);

	}
}

}`

and my respawn code: `public void Respawn () {
StartCoroutine (“RespawnCoroutine”);
}
//Routine for respawn dalay time
public IEnumerator RespawnCoroutine() {
gamePlayer.gameObject.SetActive (false);
yield return new WaitForSeconds (respawnDelay);
gamePlayer.transform.position = gamePlayer.respawnPoint;
gamePlayer.gameObject.SetActive (true);
}

}
`

Hello there,

based on your player code, you seem to be reloading the scene whenever your player die. Doing that will restart the scene EXACTLY how it was the first time, player health included… Unless you have it saved externally.

A simple fix would be to save the player’s health to PlayerPrefs. Then, on Start you can just set the currentHealth to the saved value. Note that you will have to manually manage this saved health.


I hope that helps!

Cheers,

~LegendBacon

As a fan of simple solutions:
Make a deathplane. Some trigger below the edge of your screen. When the character falls out of screen, call a script that resets their position and damages them an appropriate amount.

@Baktillus
Ive done all that, but the respawn restores health when it activates