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);*
- }*
}