Skip to content

Commit 0d94b7c

Browse files
feat: added checkpoint in endless level
1 parent 9c92464 commit 0d94b7c

13 files changed

+722
-276
lines changed

Assets/GameOverSceneManager.cs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11
using UnityEngine;
22
using UnityEngine.UI;
33
using UnityEngine.SceneManagement;
4+
using TMPro;
45

5-
/// <summary>
6-
/// This script goes in your "GameOver" scene.
7-
/// It checks the SessionManager to see if it should show the
8-
/// "Restart from Checkpoint" button.
9-
/// </summary>
106
public class GameOverSceneManager : MonoBehaviour
117
{
128
[Header("Scene Names")]
13-
[Tooltip("The name of your MAIN GAME scene")]
14-
public string gameSceneName = "MainGame"; // Make sure this matches your game scene's name
15-
16-
[Tooltip("The name of your MAIN MENU scene")]
17-
public string mainMenuSceneName = "MainMenu"; // Make sure this matches your menu scene's name
9+
public string gameSceneName = "MainGame";
10+
public string mainMenuSceneName = "MainMenu";
1811

1912
[Header("UI Buttons")]
20-
[Tooltip("Assign your 'Restart from Checkpoint' button here")]
2113
public Button restartFromCheckpointButton;
22-
23-
[Tooltip("Assign your 'Restart from Beginning' button here")]
2414
public Button restartFromBeginningButton;
25-
26-
[Tooltip("Assign your 'Main Menu' button here")]
2715
public Button mainMenuButton;
2816

17+
public TextMeshProUGUI checkpointButtonText;
18+
2919
void Start()
3020
{
31-
// Make sure the SessionManager exists
3221
if (SessionManager.Instance == null)
3322
{
3423
Debug.LogError("SessionManager not found! Cannot check for checkpoints.");
@@ -39,26 +28,27 @@ void Start()
3928
}
4029
else
4130
{
42-
// --- This is the main checkpoint logic ---
43-
if (SessionManager.Instance.LastCheckpointDistance > 0)
31+
if (SessionManager.Instance.CurrentLives > 0 && SessionManager.Instance.LastCheckpointDistance > 0)
4432
{
45-
// Player has checkpoint data, so show the button
4633
if (restartFromCheckpointButton != null)
4734
{
4835
restartFromCheckpointButton.gameObject.SetActive(true);
4936
}
37+
38+
if (checkpointButtonText != null)
39+
{
40+
checkpointButtonText.text = $"Restart from Checkpoint (Lives: {SessionManager.Instance.CurrentLives})";
41+
}
5042
}
5143
else
5244
{
53-
// No checkpoint data, so hide the button
5445
if (restartFromCheckpointButton != null)
5546
{
5647
restartFromCheckpointButton.gameObject.SetActive(false);
5748
}
5849
}
5950
}
6051

61-
// --- Add Listeners ---
6252
if (restartFromCheckpointButton != null)
6353
{
6454
restartFromCheckpointButton.onClick.AddListener(OnRestartFromCheckpoint);
@@ -77,15 +67,17 @@ void Start()
7767

7868
public void OnRestartFromCheckpoint()
7969
{
80-
// We DON'T reset the session. Just load the game scene.
81-
// The EndlessGameManager will read the checkpoint distance from SessionManager.
70+
if (SessionManager.Instance != null)
71+
{
72+
SessionManager.Instance.SpendLife();
73+
}
74+
8275
Time.timeScale = 1;
8376
SceneManager.LoadScene(gameSceneName);
8477
}
8578

8679
public void OnRestartFromBeginning()
8780
{
88-
// We MUST reset the session data before loading.
8981
if (SessionManager.Instance != null)
9082
{
9183
SessionManager.Instance.ResetSession();
@@ -97,7 +89,6 @@ public void OnRestartFromBeginning()
9789

9890
public void OnMainMenu()
9991
{
100-
// We MUST reset the session data before loading.
10192
if (SessionManager.Instance != null)
10293
{
10394
SessionManager.Instance.ResetSession();

Assets/Scenes/GameOver.unity

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -985,50 +985,6 @@ CanvasRenderer:
985985
m_PrefabAsset: {fileID: 0}
986986
m_GameObject: {fileID: 1223768745}
987987
m_CullTransparentMesh: 1
988-
--- !u!1 &1371696047
989-
GameObject:
990-
m_ObjectHideFlags: 0
991-
m_CorrespondingSourceObject: {fileID: 0}
992-
m_PrefabInstance: {fileID: 0}
993-
m_PrefabAsset: {fileID: 0}
994-
serializedVersion: 6
995-
m_Component:
996-
- component: {fileID: 1371696049}
997-
- component: {fileID: 1371696048}
998-
m_Layer: 0
999-
m_Name: GameOverManager
1000-
m_TagString: Untagged
1001-
m_Icon: {fileID: 0}
1002-
m_NavMeshLayer: 0
1003-
m_StaticEditorFlags: 0
1004-
m_IsActive: 1
1005-
--- !u!114 &1371696048
1006-
MonoBehaviour:
1007-
m_ObjectHideFlags: 0
1008-
m_CorrespondingSourceObject: {fileID: 0}
1009-
m_PrefabInstance: {fileID: 0}
1010-
m_PrefabAsset: {fileID: 0}
1011-
m_GameObject: {fileID: 1371696047}
1012-
m_Enabled: 1
1013-
m_EditorHideFlags: 0
1014-
m_Script: {fileID: 11500000, guid: c846ded251ff7e84086235844f839fe3, type: 3}
1015-
m_Name:
1016-
m_EditorClassIdentifier: '::'
1017-
--- !u!4 &1371696049
1018-
Transform:
1019-
m_ObjectHideFlags: 0
1020-
m_CorrespondingSourceObject: {fileID: 0}
1021-
m_PrefabInstance: {fileID: 0}
1022-
m_PrefabAsset: {fileID: 0}
1023-
m_GameObject: {fileID: 1371696047}
1024-
serializedVersion: 2
1025-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
1026-
m_LocalPosition: {x: 0.73243, y: 0, z: -7.58112}
1027-
m_LocalScale: {x: 1, y: 1, z: 1}
1028-
m_ConstrainProportionsScale: 0
1029-
m_Children: []
1030-
m_Father: {fileID: 0}
1031-
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1032988
--- !u!1 &1394071635
1033989
GameObject:
1034990
m_ObjectHideFlags: 0
@@ -1411,6 +1367,56 @@ Transform:
14111367
m_Children: []
14121368
m_Father: {fileID: 0}
14131369
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1370+
--- !u!1 &1915832383
1371+
GameObject:
1372+
m_ObjectHideFlags: 0
1373+
m_CorrespondingSourceObject: {fileID: 0}
1374+
m_PrefabInstance: {fileID: 0}
1375+
m_PrefabAsset: {fileID: 0}
1376+
serializedVersion: 6
1377+
m_Component:
1378+
- component: {fileID: 1915832385}
1379+
- component: {fileID: 1915832384}
1380+
m_Layer: 0
1381+
m_Name: Gameover
1382+
m_TagString: Untagged
1383+
m_Icon: {fileID: 0}
1384+
m_NavMeshLayer: 0
1385+
m_StaticEditorFlags: 0
1386+
m_IsActive: 1
1387+
--- !u!114 &1915832384
1388+
MonoBehaviour:
1389+
m_ObjectHideFlags: 0
1390+
m_CorrespondingSourceObject: {fileID: 0}
1391+
m_PrefabInstance: {fileID: 0}
1392+
m_PrefabAsset: {fileID: 0}
1393+
m_GameObject: {fileID: 1915832383}
1394+
m_Enabled: 1
1395+
m_EditorHideFlags: 0
1396+
m_Script: {fileID: 11500000, guid: c846ded251ff7e84086235844f839fe3, type: 3}
1397+
m_Name:
1398+
m_EditorClassIdentifier: Assembly-CSharp::GameOverSceneManager
1399+
gameSceneName: MainGame
1400+
mainMenuSceneName: MainMenu
1401+
restartFromCheckpointButton: {fileID: 0}
1402+
restartFromBeginningButton: {fileID: 944635826}
1403+
mainMenuButton: {fileID: 2002443025}
1404+
checkpointButtonText: {fileID: 0}
1405+
--- !u!4 &1915832385
1406+
Transform:
1407+
m_ObjectHideFlags: 0
1408+
m_CorrespondingSourceObject: {fileID: 0}
1409+
m_PrefabInstance: {fileID: 0}
1410+
m_PrefabAsset: {fileID: 0}
1411+
m_GameObject: {fileID: 1915832383}
1412+
serializedVersion: 2
1413+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
1414+
m_LocalPosition: {x: 0.08952, y: 0, z: -1.58957}
1415+
m_LocalScale: {x: 1, y: 1, z: 1}
1416+
m_ConstrainProportionsScale: 0
1417+
m_Children: []
1418+
m_Father: {fileID: 0}
1419+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
14141420
--- !u!1 &2002443023
14151421
GameObject:
14161422
m_ObjectHideFlags: 0
@@ -1553,4 +1559,4 @@ SceneRoots:
15531559
- {fileID: 17068334}
15541560
- {fileID: 1394071638}
15551561
- {fileID: 1787307106}
1556-
- {fileID: 1371696049}
1562+
- {fileID: 1915832385}

0 commit comments

Comments
 (0)