-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGameOver.cs
More file actions
50 lines (42 loc) · 1.52 KB
/
GameOver.cs
File metadata and controls
50 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameOverMenu : MonoBehaviour
{
[Tooltip("If set, this scene name will be loaded when Retry is pressed.")]
public string retrySceneName = "";
[Tooltip("Fallback build index to load when Retry is pressed. Use -1 to ignore.")]
public int retrySceneBuildIndex = -1;
[Tooltip("Optional PlayerPrefs key that stores the last played level build index. If set and present, it will be used as a fallback.")]
public string lastLevelPrefsKey = "LastLevelIndex";
public void Retry()
{
// 1) If scene name provided in inspector, load it
if (!string.IsNullOrEmpty(retrySceneName))
{
SceneManager.LoadScene(retrySceneName);
return;
}
// 2) If a valid build index is provided in inspector, load it
if (retrySceneBuildIndex >= 0)
{
SceneManager.LoadScene(retrySceneBuildIndex);
return;
}
// 3) If a PlayerPrefs key exists with last level index, use that
if (!string.IsNullOrEmpty(lastLevelPrefsKey) && PlayerPrefs.HasKey(lastLevelPrefsKey))
{
int idx = PlayerPrefs.GetInt(lastLevelPrefsKey, -1);
if (idx >= 0)
{
SceneManager.LoadScene(idx);
return;
}
}
// 4) Fallback to the previous hard-coded behaviour (scene index 1)
SceneManager.LoadScene(1);
}
public void MainMenu()
{
SceneManager.LoadScene(0);
}
}