From 388b39b511efa264f76d201b6d49b3fda644c981 Mon Sep 17 00:00:00 2001 From: rezazfn Date: Sat, 8 Feb 2025 22:49:54 +0800 Subject: [PATCH] game: misc --- Game/Assets/Scripts/BroomSweeping.cs | 20 +++++++++++-------- .../Scripts/{Sweeping.cs => SweepingTask.cs} | 2 +- ...{Sweeping.cs.meta => SweepingTask.cs.meta} | 0 3 files changed, 13 insertions(+), 9 deletions(-) rename Game/Assets/Scripts/{Sweeping.cs => SweepingTask.cs} (98%) rename Game/Assets/Scripts/{Sweeping.cs.meta => SweepingTask.cs.meta} (100%) diff --git a/Game/Assets/Scripts/BroomSweeping.cs b/Game/Assets/Scripts/BroomSweeping.cs index 9284103..d012d73 100644 --- a/Game/Assets/Scripts/BroomSweeping.cs +++ b/Game/Assets/Scripts/BroomSweeping.cs @@ -16,15 +16,19 @@ public class BroomSweeping : MonoBehaviour private void OnTriggerEnter(Collider other) { - if (!other.CompareTag("Dirt")) return; - - dirtSweeped++; - Destroy(other.gameObject); - - // Play sound only if no other sound is currently playing - if (!audioSource.isPlaying) + if (!other.CompareTag("Dirt")) { - audioSource.PlayOneShot(sweepingSound); + // Add to dirt swept count + dirtSweeped++; + + // Destroy it to prevent extra counting + Destroy(other.gameObject); + + // Play sound only if no other sound is currently playing + if (!audioSource.isPlaying) + { + audioSource.PlayOneShot(sweepingSound); + } } } } \ No newline at end of file diff --git a/Game/Assets/Scripts/Sweeping.cs b/Game/Assets/Scripts/SweepingTask.cs similarity index 98% rename from Game/Assets/Scripts/Sweeping.cs rename to Game/Assets/Scripts/SweepingTask.cs index f939b4f..cb3473e 100644 --- a/Game/Assets/Scripts/Sweeping.cs +++ b/Game/Assets/Scripts/SweepingTask.cs @@ -9,7 +9,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; -public class Sweeping : MonoBehaviour +public class SweepingTask : MonoBehaviour { public Transform broomParent; // Assign the parent object of the broom public float sweepSpeed = 2f; // Speed of automatic sweeping diff --git a/Game/Assets/Scripts/Sweeping.cs.meta b/Game/Assets/Scripts/SweepingTask.cs.meta similarity index 100% rename from Game/Assets/Scripts/Sweeping.cs.meta rename to Game/Assets/Scripts/SweepingTask.cs.meta