day increment fixed

This commit is contained in:
yauwailam 2025-02-13 20:33:40 +08:00
parent c66f9d0e76
commit 01f122af24
4 changed files with 50 additions and 47 deletions

View file

@ -260257,11 +260257,6 @@ Transform:
m_CorrespondingSourceObject: {fileID: 7049103537148308913, guid: 8af01ba72f1f55d43b1d544fb14685af, type: 3}
m_PrefabInstance: {fileID: 1340268472}
m_PrefabAsset: {fileID: 0}
--- !u!4 &1340274352 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 6045648537344725186, guid: a4a4b6738cb4ba34bb94baa14bd938f0, type: 3}
m_PrefabInstance: {fileID: 960695709}
m_PrefabAsset: {fileID: 0}
--- !u!43 &1340303700
Mesh:
m_ObjectHideFlags: 0
@ -320447,7 +320442,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1662891321}
- component: {fileID: 1662891322}
m_Layer: 0
m_Name: Spawn
m_TagString: Untagged
@ -320470,22 +320464,6 @@ Transform:
m_Children: []
m_Father: {fileID: 278618525}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1662891322
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1662891320}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c92da06a158942f46bbaa5a5a4f85d54, type: 3}
m_Name:
m_EditorClassIdentifier:
xrRig: {fileID: 1340274352}
sceneNames:
- House
- Town
--- !u!43 &1664561382
Mesh:
m_ObjectHideFlags: 0

View file

@ -27,6 +27,8 @@ public class GameManager : MonoBehaviour
private bool floorSweeped = false;
private string lastSceneName;
private bool hasIncrementedToday = false;
// Defines UI references
[Header("UI References")]
@ -73,6 +75,7 @@ public class GameManager : MonoBehaviour
{
storyText = GameObject.Find("StoryText").GetComponent<TMP_Text>();
}
SceneManager.sceneLoaded += OnSceneLoaded;
}
// Update is called once per frame
@ -155,15 +158,22 @@ public class GameManager : MonoBehaviour
// Increments the current day by 1
public void IncrementDay()
{
if (hasIncrementedToday) return; // Prevents multiple increments
hasIncrementedToday = true;
currentDay++;
Debug.Log("Day incremented to: " + currentDay); // Debug log for tracking day increment
// Checks if it's Day 4, then loads the callingChoice scene
Debug.Log("Day incremented to: " + currentDay);
if (currentDay > 3)
{
LoadCallingScene();
}
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
hasIncrementedToday = false; // Allows the day to be incremented again in the next transition
}
// Loads the callingChoice scene when Day 3 is completed
private void LoadCallingScene()

View file

@ -26,7 +26,7 @@ public class GoToSchool : MonoBehaviour
public GameObject storyPanelUI;
public TMP_Text storyText;
void Start()
void Awake()
{
gameManager = GameManager.Instance; // Reference to GameManager instance
@ -73,34 +73,46 @@ public class GoToSchool : MonoBehaviour
IEnumerator FadeInAndLoadScene()
{
// Fade In
// // Fade In
// yield return StartCoroutine(Fade(0f, 1f, fadeDuration));
//
// // Display UI for 5 seconds
// yield return new WaitForSeconds(displayDuration);
//
// // Determine the next scene based on the current day
// int currentDay = gameManager.currentDay;
// string nextScene;
//
// switch (currentDay)
// {
// case 2:
// nextScene = "Day2";
// break;
// case 3:
// nextScene = "Day3"; // need another way to go to day 3 tho bcos they arent going to sch on day 3
// break;
// default:
// nextScene = "Start"; // Fallback in case of unexpected day value
// break;
// }
//
// // Load the determined next scene
// SceneManager.LoadScene(nextScene);
//
// // Increment the day AFTER transitioning to avoid multiple increments
// gameManager.IncrementDay();
yield return StartCoroutine(Fade(0f, 1f, fadeDuration));
// Display UI for 5 seconds
yield return new WaitForSeconds(displayDuration);
// Determine the next scene based on the current day
int currentDay = gameManager.currentDay;
string nextScene;
string nextScene = currentDay == 2 ? "Day2" : (currentDay == 3 ? "Day3" : "Start");
switch (currentDay)
{
case 2:
nextScene = "Day2";
break;
case 3:
nextScene = "Day3"; // need another way to go to day 3 tho bcos they arent going to sch on day 3
break;
default:
nextScene = "Start"; // Fallback in case of unexpected day value
break;
}
// Load the determined next scene
SceneManager.LoadScene(nextScene);
// Increment the day AFTER transitioning to avoid multiple increments
gameManager.IncrementDay();
yield return new WaitForSeconds(1f); // Small delay to ensure scene transition
gameManager.IncrementDay(); // Now called *after* scene fully loads
}
IEnumerator Fade(float startAlpha, float endAlpha, float duration)

View file

@ -26,6 +26,9 @@ EditorBuildSettings:
- enabled: 1
path: Assets/Scenes/Town.unity
guid: 34ddf74f9d161b149ad0af6f15f9ed1a
- enabled: 1
path: Assets/Scenes/Day2.unity
guid: 16cbfc040f037e6479359f442ef826bd
m_configObjects:
Unity.XR.Oculus.Settings: {fileID: 11400000, guid: bfa1182bd221b4ca89619141f66f1260, type: 2}
Unity.XR.WindowsMR.Settings: {fileID: 11400000, guid: dc5a169419fa04987b057f65238cf3ba, type: 2}