2025-02-10 12:20:10 +08:00
|
|
|
/*
|
|
|
|
Author: Reza
|
|
|
|
Date: 7/2/25
|
|
|
|
Description: Detects dirt and sweeps them up
|
|
|
|
*/
|
|
|
|
|
2025-02-07 21:46:20 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2025-02-11 09:55:06 +08:00
|
|
|
using TMPro;
|
2025-02-07 21:46:20 +08:00
|
|
|
|
|
|
|
public class BroomSweeping : MonoBehaviour
|
|
|
|
{
|
2025-02-11 09:55:06 +08:00
|
|
|
private GameManager gameManager;
|
|
|
|
private PostProcessingManager postProcessingManager;
|
2025-02-12 00:55:33 +08:00
|
|
|
private StorylineManager storylineManager;
|
2025-02-11 09:55:06 +08:00
|
|
|
|
2025-02-07 21:46:20 +08:00
|
|
|
// To track how much trash has been collected so far
|
|
|
|
public int dirtSweeped = 0;
|
|
|
|
|
|
|
|
// Defines how much trash is needed to collect in order to unlock the door
|
|
|
|
public int dirtRequired = 10;
|
|
|
|
|
2025-02-11 15:01:17 +08:00
|
|
|
private bool taskCompleted = false;
|
|
|
|
|
2025-02-11 09:55:06 +08:00
|
|
|
// Defines UI references
|
|
|
|
[Header("UI References")]
|
2025-02-12 00:55:33 +08:00
|
|
|
//public GameObject storyPanelUI;
|
2025-02-11 09:55:06 +08:00
|
|
|
public TMP_Text storyText;
|
|
|
|
|
2025-02-07 21:46:20 +08:00
|
|
|
// Defines Audio References
|
2025-02-11 09:55:06 +08:00
|
|
|
[Header("Audio References")]
|
2025-02-07 21:46:20 +08:00
|
|
|
public AudioSource audioSource;
|
|
|
|
public AudioClip sweepingSound;
|
2025-02-12 00:55:33 +08:00
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
storylineManager = FindObjectOfType<StorylineManager>();
|
|
|
|
}
|
|
|
|
|
2025-02-11 09:55:06 +08:00
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2025-02-11 15:01:17 +08:00
|
|
|
if (dirtSweeped >= dirtRequired && !taskCompleted)
|
2025-02-11 09:55:06 +08:00
|
|
|
{
|
2025-02-11 15:01:17 +08:00
|
|
|
taskCompleted = true;
|
2025-02-11 09:55:06 +08:00
|
|
|
GameManager.Instance.FloorSweepedTaskComplete();
|
|
|
|
|
2025-02-12 00:55:33 +08:00
|
|
|
//storyPanelUI.SetActive(true);
|
|
|
|
//storyText.text = "I hope the house is clean enough now so I don't get scolded later...";
|
|
|
|
|
|
|
|
storylineManager.EnqueueMessage("I tried my best... Hopefully I don't get scolded later.", 7f);
|
2025-02-11 16:35:16 +08:00
|
|
|
|
2025-02-12 00:55:33 +08:00
|
|
|
//StartCoroutine(ClearMessageAfterSeconds(7f));
|
2025-02-11 09:55:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-07 21:46:20 +08:00
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
2025-02-11 15:01:17 +08:00
|
|
|
// Now correctly checks for "Dirt" before triggering
|
|
|
|
if (other.CompareTag("Dirt"))
|
2025-02-07 21:46:20 +08:00
|
|
|
{
|
2025-02-08 22:49:54 +08:00
|
|
|
dirtSweeped++;
|
2025-02-11 15:01:17 +08:00
|
|
|
|
2025-02-08 22:49:54 +08:00
|
|
|
// Destroy it to prevent extra counting
|
|
|
|
Destroy(other.gameObject);
|
2025-02-11 15:01:17 +08:00
|
|
|
|
2025-02-08 22:49:54 +08:00
|
|
|
// Play sound only if no other sound is currently playing
|
|
|
|
if (!audioSource.isPlaying)
|
|
|
|
{
|
|
|
|
audioSource.PlayOneShot(sweepingSound);
|
|
|
|
}
|
2025-02-07 21:46:20 +08:00
|
|
|
}
|
|
|
|
}
|
2025-02-11 15:01:17 +08:00
|
|
|
|
|
|
|
private IEnumerator ClearMessageAfterSeconds(float delay)
|
2025-02-11 09:55:06 +08:00
|
|
|
{
|
|
|
|
// Waits for delay to end and hides the UI
|
|
|
|
yield return new WaitForSeconds(delay);
|
2025-02-11 15:01:17 +08:00
|
|
|
storyText.text = "";
|
2025-02-11 09:55:06 +08:00
|
|
|
}
|
2025-02-07 21:46:20 +08:00
|
|
|
}
|