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;
private Player playerScript;
[SerializeField] private GameObject npcObject;
public GameObject npcObject;
private string correctDirection;
private string directionSent;
void Start()
{
npcMoveScript = npcObject.GetComponent<NPCMovement>();
npcBehaviourScript = npcObject.GetComponent<NPCBehaviour>();
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()
{
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";

View file

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

View file

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

View file

@ -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()

View file

@ -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)
{