game(scripts): standardise BedroomTask

This commit is contained in:
Mark Joshwel 2025-02-14 22:05:16 +08:00
parent fb236bd1bc
commit 23122b395b

View file

@ -106,12 +106,10 @@ public class BedroomTask : MonoBehaviour
{ {
yield return new WaitForSeconds(0.5f); // Small delay to ensure a smooth transition yield return new WaitForSeconds(0.5f); // Small delay to ensure a smooth transition
if (storyPanelUI != null && storyText != null) if (!storyPanelUI || storyText == null) yield break;
{ storyPanelUI.SetActive(true);
storyPanelUI.SetActive(true); storyText.text = "My parents are still home... I should clean up first.";
storyText.text = "My parents are still home... I should clean up first."; StartCoroutine(ClearMessageAfterSeconds(7f));
StartCoroutine(ClearMessageAfterSeconds(7f));
}
} }
// Functions when trash is collected/thrown // Functions when trash is collected/thrown
@ -126,16 +124,15 @@ public class BedroomTask : MonoBehaviour
Debug.Log($"Trash collected: {trashCollected}/{trashRequired}"); Debug.Log($"Trash collected: {trashCollected}/{trashRequired}");
// If the player has collected/ thrown the required amount of trash // If the player has collected/ thrown the required amount of trash
if (trashCollected >= trashRequired) if (trashCollected < trashRequired) return;
{
if (GameManager.Instance == null) if (GameManager.Instance == null)
Debug.LogError("GameManager instance is null!"); Debug.LogError("GameManager instance is null!");
else else
GameManager.Instance.BedroomTaskComplete(); GameManager.Instance.BedroomTaskComplete();
// Call unlocking door function/sequence // Call unlocking door function/sequence
StartCoroutine(PlaySoundSequence()); StartCoroutine(PlaySoundSequence());
}
} }
// Functions when the door is locked // Functions when the door is locked
@ -190,18 +187,17 @@ public class BedroomTask : MonoBehaviour
private void OnDoorGrabAttempt(SelectEnterEventArgs args) private void OnDoorGrabAttempt(SelectEnterEventArgs args)
{ {
// If the amount of trash collected is lesser than the required amount // If the amount of trash collected is lesser than the required amount
if (trashCollected < trashRequired) if (trashCollected >= trashRequired) return;
{
// Show the locked door UI
lockedDoorUI.SetActive(true);
// Play sound only if no other sound is currently playing // Show the locked door UI
if (!audioSource.isPlaying) audioSource.PlayOneShot(lockedSound); lockedDoorUI.SetActive(true);
// Call the function to hide the UI after delay // Play sound only if no other sound is currently playing
StartCoroutine(HidePanelAfterSeconds(lockedDoorUI, 5f)); if (!audioSource.isPlaying) audioSource.PlayOneShot(lockedSound);
Debug.Log("The door is locked! Clean the room first.");
} // Call the function to hide the UI after delay
StartCoroutine(HidePanelAfterSeconds(lockedDoorUI, 5f));
Debug.Log("The door is locked! Clean the room first.");
} }
// Function when the task is completed // Function when the task is completed