game(scripts): polished bedroom task and brush teeth task to update gamemanager
This commit is contained in:
parent
a3a8eaf852
commit
d8d40f1aa5
4 changed files with 55 additions and 6 deletions
|
@ -86823,10 +86823,18 @@ PrefabInstance:
|
|||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 745726886}
|
||||
m_Modifications:
|
||||
- target: {fileID: 806528791475834742, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
|
||||
propertyPath: audioSource
|
||||
value:
|
||||
objectReference: {fileID: 1898819871}
|
||||
- target: {fileID: 806528791475834742, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
|
||||
propertyPath: progressBar
|
||||
value:
|
||||
objectReference: {fileID: 1902891356}
|
||||
- target: {fileID: 806528791475834742, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
|
||||
propertyPath: brushingSound
|
||||
value:
|
||||
objectReference: {fileID: 8300000, guid: 9cf02b0277ad0324389ae25a9fefe8ba, type: 3}
|
||||
- target: {fileID: 3017716152663212623, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -0.184021
|
||||
|
@ -86873,7 +86881,7 @@ PrefabInstance:
|
|||
objectReference: {fileID: 430002287}
|
||||
- target: {fileID: 3408018161587624474, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
|
||||
propertyPath: m_VersionIndex
|
||||
value: 1679
|
||||
value: 1685
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5470122699805207955, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
|
||||
propertyPath: m_Mesh
|
||||
|
|
|
@ -14,6 +14,8 @@ using UnityEngine.XR.Interaction.Toolkit;
|
|||
|
||||
public class BedroomTask : MonoBehaviour
|
||||
{
|
||||
private GameManager gameManager;
|
||||
|
||||
[Header("Task Requirement Values")]
|
||||
// To track how much trash has been collected so far
|
||||
public int trashCollected = 0;
|
||||
|
@ -99,7 +101,7 @@ public class BedroomTask : MonoBehaviour
|
|||
// If player has collected/thrown required amount of trash
|
||||
if (trashCollected >= trashRequired)
|
||||
{
|
||||
Debug.Log("Trash requirement met! Starting sound sequence...");
|
||||
GameManager.Instance.BedroomTaskComplete();
|
||||
|
||||
// Call unlocking door function/sequence
|
||||
StartCoroutine(PlaySoundSequence());
|
||||
|
@ -147,6 +149,12 @@ public class BedroomTask : MonoBehaviour
|
|||
doorCollider.enabled = true;
|
||||
}
|
||||
|
||||
// Play sound only if no other sound is currently playing
|
||||
if (!audioSource.isPlaying)
|
||||
{
|
||||
audioSource.PlayOneShot(unlockedSound);
|
||||
}
|
||||
|
||||
// Show the unlocked door UI
|
||||
unlockedDoorUI.SetActive(true);
|
||||
|
||||
|
@ -185,8 +193,6 @@ public class BedroomTask : MonoBehaviour
|
|||
|
||||
private IEnumerator PlaySoundSequence()
|
||||
{
|
||||
Debug.Log("Starting PlaySoundSequence...");
|
||||
|
||||
// Play footsteps of parents walking away
|
||||
audioSource.PlayOneShot(footstepsSound);
|
||||
yield return new WaitForSeconds(footstepsSound.length);
|
||||
|
@ -197,6 +203,7 @@ public class BedroomTask : MonoBehaviour
|
|||
|
||||
// Unlocks the door after the clips and update the story
|
||||
UnlockDoor();
|
||||
|
||||
storyText.text = "They finally left... just as soon as I finished cleaning. I can leave the room now.";
|
||||
storyPanelUI.SetActive(true);
|
||||
StartCoroutine(HideMessageAfterSeconds(storyPanelUI, 10f));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Author: Wai Lam
|
||||
Author: Wai Lam & Reza
|
||||
Date: 27/1/25
|
||||
Description: Bathroom interaction
|
||||
*/
|
||||
|
@ -14,13 +14,17 @@ using UnityEngine.XR.Interaction.Toolkit.Interactors;
|
|||
|
||||
public class BrushTeeth : MonoBehaviour
|
||||
{
|
||||
public PostProcessingManager postProcessingManager;
|
||||
private GameManager gameManager;
|
||||
|
||||
public Slider progressBar; // Reference to the Slider (progress bar)
|
||||
public float progressTime = 5f; // Time for the progress bar to complete
|
||||
private XRGrabInteractable grabInteractable;
|
||||
private float timer = 0f;
|
||||
private bool isGrabbing = false;
|
||||
|
||||
// Audio References
|
||||
public AudioSource audioSource;
|
||||
public AudioClip brushingSound;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
@ -67,6 +71,17 @@ public class BrushTeeth : MonoBehaviour
|
|||
progressBar.value = 0f;
|
||||
timer = 0f;
|
||||
isGrabbing = true;
|
||||
|
||||
// Play brushing sound while toothbrush is grabbed, plays only if it isn't playing already
|
||||
if (!audioSource.isPlaying)
|
||||
{
|
||||
audioSource.clip = brushingSound;
|
||||
|
||||
// Loops the sound for as long as the toothbrush is held; allows editable progress time
|
||||
audioSource.loop = true;
|
||||
|
||||
audioSource.Play();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRelease(SelectExitEventArgs args)
|
||||
|
@ -75,12 +90,26 @@ public class BrushTeeth : MonoBehaviour
|
|||
progressBar.gameObject.SetActive(false);
|
||||
isGrabbing = false;
|
||||
timer = 0f;
|
||||
|
||||
// Stop the brushing sound when the toothbrush is released
|
||||
if (audioSource.isPlaying)
|
||||
{
|
||||
audioSource.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void CompleteProgress()
|
||||
{
|
||||
progressBar.gameObject.SetActive(false);
|
||||
isGrabbing = false;
|
||||
|
||||
// Stop the brushing sound when the task is completed
|
||||
if (audioSource.isPlaying)
|
||||
{
|
||||
audioSource.Stop();
|
||||
}
|
||||
|
||||
GameManager.Instance.BrushTeethTaskComplete();
|
||||
|
||||
Debug.Log("Progress completed!");
|
||||
}
|
||||
|
|
|
@ -65,4 +65,9 @@ public class GameManager : MonoBehaviour
|
|||
{
|
||||
bedroomCleaned = true;
|
||||
}
|
||||
|
||||
public void BrushTeethTaskComplete()
|
||||
{
|
||||
teethBrushed = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue