Continue on death screen

hello all,

i am creating a simple 2D endless runner for my first unity project and I’m new to scripting so could really use some help. I am having an absolute nightmare with adding a ‘Continue’ UI button to my “you Died” screen. I have a fully working UI for Restarting or exiting to main menu but i want to add a Continue button that allows the player to continue from the position that they died but only once. i have a death menu script and a game manager script that link into each other that i will post below. i know there is a fair bit of script there but as i just need to add in a continue section I’m not sure where to add it in.

any help is MAJORLY appreciated.

Game Manager Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour {

public static GameManager instance;
public float ScrollSpeed = -1.5f;
public Transform platformGenerator;
private Vector3 platformStartPoint;

public PlayerController thePlayer;
private Vector3 playerStartPoint;

private PlatformDestroyer[] platformlist;

private ScoreManager theScoreManager;

public DeathMenu theDeathScreen;

public bool powerupReset;

void Awake ()
{
	if (instance == null) {
		instance = this;
	} else if (instance!= this)
	{
		Destroy (gameObject);
	}
}

// Use this for initialization
void Start ()
{
	platformStartPoint = platformGenerator.position;
	playerStartPoint = thePlayer.transform.position;

	theScoreManager = FindObjectOfType<ScoreManager> ();
}

public void RestartGame()
{
	theScoreManager.scoreIncreasing = false;
	thePlayer.gameObject.SetActive(false);

	theDeathScreen.gameObject.SetActive (true);

	//StartCoroutine ("RestartGameCo");
}

public void Reset()
{
	theDeathScreen.gameObject.SetActive (false);
	platformlist = FindObjectsOfType<PlatformDestroyer> ();
	for(int i = 0; i < platformlist.Length; i++)
	{
		platformlist*.gameObject.SetActive(false);*
  •   }*
    
  •   thePlayer.transform.position = playerStartPoint;*
    
  •   platformGenerator.position = platformStartPoint;*
    
  •   thePlayer.gameObject.SetActive (true);*
    
  •   theScoreManager.scoreCount = 0;*
    
  •   theScoreManager.scoreIncreasing = true;*
    
  •   powerupReset = true;*
    
  • }*
    }
    DeathMenu Script:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    public class DeathMenu : MonoBehaviour {
  • public string mainMenuLevel;*
  • public void RestartGame()*
  • {*
  •   FindObjectOfType<GameManager>().Reset();*
    
  • }*
  • public void QuitToMain()*
  • {*
  •   SceneManager.LoadScene(mainMenuLevel);*
    
  • }*
    }

@Kiesco32

Do you mean you want the ability to continue after death with the same score and everything else the same?
If so then you would want to save everything then make sure to set the variables up like this:

int lastScore = currentScore;
Vector3 lastPosition = transform.position;

And then you can do something like this when the player is dead:

void Continue(int lastScore, Vector3 lastPosition) {
    currentScore = lastScore;
    currentPosition = lastPosition;
}

@KittenSnipes really sorry for being useless but I’m really stuck on where to put your code. i have put it in the death menu as my retry and exit buttons link from that script but it doesn’t want to work.

any suggestions?

thanks in advance :slight_smile: