game(scripts): standardise BroomSweeping
This commit is contained in:
parent
810ca3d91d
commit
fb236bd1bc
1 changed files with 26 additions and 31 deletions
|
@ -1,56 +1,54 @@
|
||||||
/*
|
/*
|
||||||
Author: Reza
|
* Author: Reza
|
||||||
Date: 7/2/25
|
* Date: 7/2/25
|
||||||
Description: Detects dirt and sweeps them up
|
* Description: Detects dirt and sweeps them up
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
public class BroomSweeping : MonoBehaviour
|
public class BroomSweeping : MonoBehaviour
|
||||||
{
|
{
|
||||||
private GameManager gameManager;
|
|
||||||
private PostProcessingManager PostProcessingManager;
|
|
||||||
|
|
||||||
// To track how much trash has been collected so far
|
// To track how much trash has been collected so far
|
||||||
public int dirtSweeped = 0;
|
public int dirtSweeped;
|
||||||
|
|
||||||
// Defines how much trash is needed to collect in order to unlock the door
|
// Defines how much trash is needed to collect in order to unlock the door
|
||||||
public int dirtRequired = 10;
|
public int dirtRequired = 10;
|
||||||
|
|
||||||
private bool taskCompleted = false;
|
|
||||||
|
|
||||||
// Defines UI references
|
// Defines UI references
|
||||||
[Header("UI References")]
|
[Header("UI References")] public GameObject storyPanelUI;
|
||||||
public GameObject storyPanelUI;
|
|
||||||
public TMP_Text storyText;
|
public TMP_Text storyText;
|
||||||
|
|
||||||
// Defines Audio References
|
// Defines Audio References
|
||||||
[Header("Audio References")]
|
[Header("Audio References")] public AudioSource audioSource;
|
||||||
public AudioSource audioSource;
|
|
||||||
public AudioClip sweepingSound;
|
public AudioClip sweepingSound;
|
||||||
|
private GameManager gameManager;
|
||||||
|
private PostProcessingManager PostProcessingManager;
|
||||||
|
|
||||||
|
private bool taskCompleted;
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (dirtSweeped >= dirtRequired && !taskCompleted)
|
if (dirtSweeped >= dirtRequired && !taskCompleted)
|
||||||
{
|
{
|
||||||
taskCompleted = true;
|
taskCompleted = true;
|
||||||
GameManager.Instance.FloorSweepedTaskComplete();
|
GameManager.Instance.FloorSweepedTaskComplete();
|
||||||
|
|
||||||
storyPanelUI.SetActive(true);
|
storyPanelUI.SetActive(true);
|
||||||
storyText.text = "I hope the house is clean enough now so I don't get scolded later...";
|
storyText.text = "I hope the house is clean enough now so I don't get scolded later...";
|
||||||
|
|
||||||
StartCoroutine(ClearMessageAfterSeconds(7f));
|
StartCoroutine(ClearMessageAfterSeconds(7f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTriggerEnter(Collider other)
|
private void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
// Now correctly checks for "Dirt" before triggering
|
// Now correctly checks for "Dirt" before triggering
|
||||||
if (other.CompareTag("Dirt"))
|
if (other.CompareTag("Dirt"))
|
||||||
{
|
{
|
||||||
dirtSweeped++;
|
dirtSweeped++;
|
||||||
|
|
||||||
|
@ -58,13 +56,10 @@ public class BroomSweeping : MonoBehaviour
|
||||||
Destroy(other.gameObject);
|
Destroy(other.gameObject);
|
||||||
|
|
||||||
// Play sound only if no other sound is currently playing
|
// Play sound only if no other sound is currently playing
|
||||||
if (!audioSource.isPlaying)
|
if (!audioSource.isPlaying) audioSource.PlayOneShot(sweepingSound);
|
||||||
{
|
|
||||||
audioSource.PlayOneShot(sweepingSound);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator ClearMessageAfterSeconds(float delay)
|
private IEnumerator ClearMessageAfterSeconds(float delay)
|
||||||
{
|
{
|
||||||
// Waits for delay to end and hides the UI
|
// Waits for delay to end and hides the UI
|
||||||
|
|
Loading…
Add table
Reference in a new issue