game: fixing npc spawn references

buttons not working (push buttons)
This commit is contained in:
kookiekenobi 2025-02-04 12:19:52 +08:00
parent 27f278bf3a
commit 7c9f2d4df9
5 changed files with 34 additions and 8 deletions

View file

@ -15,20 +15,36 @@ public class DeskButtons : MonoBehaviour
NPCBehaviour npcBehaviourScript; NPCBehaviour npcBehaviourScript;
private Player playerScript; private Player playerScript;
[SerializeField] private GameObject npcObject; public GameObject npcObject;
private string correctDirection; private string correctDirection;
private string directionSent; private string directionSent;
void Start() void Start()
{ {
npcMoveScript = npcObject.GetComponent<NPCMovement>();
npcBehaviourScript = npcObject.GetComponent<NPCBehaviour>();
playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>(); playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
} }
void UpdateNPCReferences()
{
GameObject npcObject = GameManager.instance.currentNPC;
if (npcObject != null)
{
npcMoveScript = npcObject.GetComponent<NPCMovement>();
npcBehaviourScript = npcObject.GetComponent<NPCBehaviour>();
}
}
public void DirectToLeft() public void DirectToLeft()
{ {
UpdateNPCReferences();
if (npcMoveScript == null || npcBehaviourScript == null)
{
Debug.LogWarning("NPC references are null");
return;
}
npcMoveScript.WalkToPlayerLeft(); npcMoveScript.WalkToPlayerLeft();
directionSent = "left"; directionSent = "left";
@ -46,6 +62,13 @@ public class DeskButtons : MonoBehaviour
public void DirectToRight() public void DirectToRight()
{ {
UpdateNPCReferences();
if (npcMoveScript == null || npcBehaviourScript == null)
{
Debug.LogWarning("NPC references are null");
return;
}
npcMoveScript.WalkToPlayerRight(); npcMoveScript.WalkToPlayerRight();
directionSent = "right"; directionSent = "right";

View file

@ -19,11 +19,10 @@ public class GameManager : MonoBehaviour
/// <summary> /// <summary>
/// References and Variables /// References and Variables
/// </summary> /// </summary>
[SerializeField]
public bool dayEnded = false; public bool dayEnded = false;
[SerializeField]
public bool shiftStarted; public bool shiftStarted;
public GameObject currentNPC;
[Header("Walk Points (FOR DEBUGGING")] [Header("Walk Points (FOR DEBUGGING")]
public Transform[] frontWalkPoints; public Transform[] frontWalkPoints;

View file

@ -33,6 +33,8 @@ public class NPCMovement : MonoBehaviour
/// </summary> /// </summary>
void Start() void Start()
{ {
gm = GameManager.instance;
StartCoroutine(WalkingToPlayer()); StartCoroutine(WalkingToPlayer());
} }

View file

@ -23,8 +23,10 @@ public class NPCSpawn : MonoBehaviour
void SpawnNPC() void SpawnNPC()
{ {
StopAllCoroutines(); StopAllCoroutines();
Instantiate(npc, transform.position, Quaternion.identity); GameObject spawnedNPC = Instantiate(npc, transform.position, Quaternion.identity);
npcSpawned = true; npcSpawned = true;
GameManager.instance.currentNPC = spawnedNPC;
} }
IEnumerator SpawnNPCAfterWait() IEnumerator SpawnNPCAfterWait()

View file

@ -45,7 +45,7 @@ public class ShiftManager : MonoBehaviour
while (remainingTime > 0) while (remainingTime > 0)
{ {
remainingTime -= Time.deltaTime; remainingTime -= Time.deltaTime;
Debug.Log("Shift: " + remainingTime); /*Debug.Log("Shift: " + remainingTime);*/
if (Player.score < 0) if (Player.score < 0)
{ {