diff --git a/SSLR/Assets/Scripts/DeskButtons.cs b/SSLR/Assets/Scripts/DeskButtons.cs index 9b31ae9..c56c191 100644 --- a/SSLR/Assets/Scripts/DeskButtons.cs +++ b/SSLR/Assets/Scripts/DeskButtons.cs @@ -15,20 +15,36 @@ public class DeskButtons : MonoBehaviour NPCBehaviour npcBehaviourScript; private Player playerScript; - [SerializeField] private GameObject npcObject; + public GameObject npcObject; private string correctDirection; private string directionSent; void Start() { - npcMoveScript = npcObject.GetComponent(); - npcBehaviourScript = npcObject.GetComponent(); playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent(); } + void UpdateNPCReferences() + { + GameObject npcObject = GameManager.instance.currentNPC; + + if (npcObject != null) + { + npcMoveScript = npcObject.GetComponent(); + npcBehaviourScript = npcObject.GetComponent(); + } + } + public void DirectToLeft() { + UpdateNPCReferences(); + if (npcMoveScript == null || npcBehaviourScript == null) + { + Debug.LogWarning("NPC references are null"); + return; + } + npcMoveScript.WalkToPlayerLeft(); directionSent = "left"; @@ -46,6 +62,13 @@ public class DeskButtons : MonoBehaviour public void DirectToRight() { + UpdateNPCReferences(); + if (npcMoveScript == null || npcBehaviourScript == null) + { + Debug.LogWarning("NPC references are null"); + return; + } + npcMoveScript.WalkToPlayerRight(); directionSent = "right"; diff --git a/SSLR/Assets/Scripts/GameManager.cs b/SSLR/Assets/Scripts/GameManager.cs index 09330f1..680f45e 100644 --- a/SSLR/Assets/Scripts/GameManager.cs +++ b/SSLR/Assets/Scripts/GameManager.cs @@ -19,11 +19,10 @@ public class GameManager : MonoBehaviour /// /// References and Variables /// - [SerializeField] public bool dayEnded = false; - - [SerializeField] public bool shiftStarted; + + public GameObject currentNPC; [Header("Walk Points (FOR DEBUGGING")] public Transform[] frontWalkPoints; diff --git a/SSLR/Assets/Scripts/NPCMovement.cs b/SSLR/Assets/Scripts/NPCMovement.cs index fca34c0..f2b1082 100644 --- a/SSLR/Assets/Scripts/NPCMovement.cs +++ b/SSLR/Assets/Scripts/NPCMovement.cs @@ -33,6 +33,8 @@ public class NPCMovement : MonoBehaviour /// void Start() { + gm = GameManager.instance; + StartCoroutine(WalkingToPlayer()); } diff --git a/SSLR/Assets/Scripts/NPCSpawn.cs b/SSLR/Assets/Scripts/NPCSpawn.cs index d3a863c..99ae71d 100644 --- a/SSLR/Assets/Scripts/NPCSpawn.cs +++ b/SSLR/Assets/Scripts/NPCSpawn.cs @@ -23,8 +23,10 @@ public class NPCSpawn : MonoBehaviour void SpawnNPC() { StopAllCoroutines(); - Instantiate(npc, transform.position, Quaternion.identity); + GameObject spawnedNPC = Instantiate(npc, transform.position, Quaternion.identity); npcSpawned = true; + + GameManager.instance.currentNPC = spawnedNPC; } IEnumerator SpawnNPCAfterWait() diff --git a/SSLR/Assets/Scripts/ShiftManager.cs b/SSLR/Assets/Scripts/ShiftManager.cs index 7623234..c13ee6b 100644 --- a/SSLR/Assets/Scripts/ShiftManager.cs +++ b/SSLR/Assets/Scripts/ShiftManager.cs @@ -45,7 +45,7 @@ public class ShiftManager : MonoBehaviour while (remainingTime > 0) { remainingTime -= Time.deltaTime; - Debug.Log("Shift: " + remainingTime); + /*Debug.Log("Shift: " + remainingTime);*/ if (Player.score < 0) {