From a01b6778aab07f99842869d14f21e129516df2e9 Mon Sep 17 00:00:00 2001 From: kookiekenobi Date: Wed, 5 Feb 2025 02:30:22 +0800 Subject: [PATCH] game: fixed npc despawning logic --- SSLR/Assets/Scripts/Despawn.cs | 8 +++----- SSLR/Assets/Scripts/NPCSpawn.cs | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/SSLR/Assets/Scripts/Despawn.cs b/SSLR/Assets/Scripts/Despawn.cs index d8bd134..7bed0ca 100644 --- a/SSLR/Assets/Scripts/Despawn.cs +++ b/SSLR/Assets/Scripts/Despawn.cs @@ -23,12 +23,10 @@ public class Despawn : MonoBehaviour { if (other.CompareTag("NPC")) { - other.gameObject.SetActive(false); + GameManager.instance.currentNPC = null; + NPCSpawn.instance.npcSpawned = false; + Destroy(other.gameObject); - - npcSpawnScript.npcSpawned = false; } } - - } diff --git a/SSLR/Assets/Scripts/NPCSpawn.cs b/SSLR/Assets/Scripts/NPCSpawn.cs index 99ae71d..07ba14f 100644 --- a/SSLR/Assets/Scripts/NPCSpawn.cs +++ b/SSLR/Assets/Scripts/NPCSpawn.cs @@ -4,14 +4,26 @@ using UnityEngine; public class NPCSpawn : MonoBehaviour { + public static NPCSpawn instance; + [SerializeField] private float npcBufferTime; public bool npcSpawned = false; - /*[SerializeField] - List NPCs = new List();*/ [SerializeField] GameObject npc; + void Awake() + { + if (instance ==null) + { + instance = this; + } + else + { + Destroy(gameObject); + } + } + void Update() { if (!npcSpawned)