game: fixed the endless walking

This commit is contained in:
ryan 2025-02-18 02:47:20 +08:00
parent 833fb0b50b
commit 2adf242307
4 changed files with 45 additions and 39 deletions

View file

@ -21,6 +21,7 @@ public class NpcMovementRework : MonoBehaviour
/// Animation assigning /// Animation assigning
/// </summary> /// </summary>
public Animator animator; public Animator animator;
private static readonly int IsSitting = Animator.StringToHash("isSitting"); private static readonly int IsSitting = Animator.StringToHash("isSitting");
private static readonly int Speed = Animator.StringToHash("Speed"); private static readonly int Speed = Animator.StringToHash("Speed");
@ -28,6 +29,7 @@ public class NpcMovementRework : MonoBehaviour
/// NPC's dialogue variables /// NPC's dialogue variables
/// </summary> /// </summary>
public TextMeshProUGUI npcWelcomeText; public TextMeshProUGUI npcWelcomeText;
public TextMeshProUGUI initialStatementText; public TextMeshProUGUI initialStatementText;
public TextMeshProUGUI npcAnswerOneText; public TextMeshProUGUI npcAnswerOneText;
public TextMeshProUGUI npcAnswerTwoText; public TextMeshProUGUI npcAnswerTwoText;
@ -41,7 +43,7 @@ public class NpcMovementRework : MonoBehaviour
/// NPC Data referemce /// NPC Data referemce
/// </summary> /// </summary>
public NpcData npcData; public NpcData npcData;
/// <summary> /// <summary>
/// Variable to store service /// Variable to store service
/// </summary> /// </summary>
@ -74,54 +76,33 @@ public class NpcMovementRework : MonoBehaviour
npcSpeechBubble.SetActive(false); npcSpeechBubble.SetActive(false);
npcAnswerPanel.SetActive(false); npcAnswerPanel.SetActive(false);
StartCoroutine(SitDown()); StartCoroutine(SitDown());
} }
/// <summary>
/// Call coroutine to call client
/// </summary>
public void Called()
{
StartCoroutine(CustomerCalled());
}
/// <summary> /// <summary>
/// Coroutine to get NPC to coe to table /// Coroutine to get NPC to coe to table
/// </summary> /// </summary>
/// <returns></returns> public void CustomerCalled()
public IEnumerator CustomerCalled()
{ {
animator.SetBool(IsSitting, false); animator.SetBool(IsSitting, false);
var pos = NpcManager.instance.desk; var pos = NpcManager.instance.desk;
agent.SetDestination(pos.position); agent.SetDestination(pos.position);
while (true) var npcpos = gameObject.transform.position;
{ npcpos.y = 0;
var npcpos = gameObject.transform.position; }
npcpos.y = 0;
var dist = Vector3.Distance(pos.position, npcpos);
if (dist < 1.0f) public void Stop()
{ {
agent.SetDestination(gameObject.transform.position); agent.SetDestination(gameObject.transform.position);
gameObject.transform.rotation = pos.transform.rotation; GameManager.instance.SetCurrentNPC(this.gameObject);
GameManager.instance.SetCurrentNPC(this.gameObject); npcSpeechBubble.SetActive(true);
npcAnswerPanel.SetActive(true);
PlayerDialogueInteraction.instance.playerDialogue.SetActive(true);
correctService = npcData.correctDepartment;
npcSpeechBubble.SetActive(true); LoadNPCDialogue();
npcAnswerPanel.SetActive(true);
PlayerDialogueInteraction.instance.playerDialogue.SetActive(true);
yield return new WaitUntil(() => npcData != null);
correctService = npcData.correctDepartment;
LoadNPCDialogue();
break;
}
yield return 0;
}
} }
@ -139,10 +120,10 @@ public class NpcMovementRework : MonoBehaviour
seat = NpcManager.instance.Seats[i]; seat = NpcManager.instance.Seats[i];
yield return new WaitForSeconds(2f); yield return new WaitForSeconds(2f);
} }
seat.Available = false; seat.Available = false;
var sittingPosition = seat.SeatObject.transform.position; var sittingPosition = seat.SeatObject.transform.position;
agent.SetDestination(sittingPosition); agent.SetDestination(sittingPosition);
Debug.Log("Sitting down"); Debug.Log("Sitting down");
while (true) while (true)
@ -160,7 +141,7 @@ public class NpcMovementRework : MonoBehaviour
yield return 0; yield return 0;
} }
} }
/// <summary> /// <summary>
/// Despawning NPCs /// Despawning NPCs

View file

@ -20,7 +20,7 @@ public class NextButton : MonoBehaviour
var randomnpc = npcs[Random.Range(0, npcs.Count)]; var randomnpc = npcs[Random.Range(0, npcs.Count)];
GameManager.instance.SetCurrentNPC(randomnpc); GameManager.instance.SetCurrentNPC(randomnpc);
randomnpc.GetComponent<NpcMovementRework>().Called(); randomnpc.GetComponent<NpcMovementRework>().CustomerCalled();
PlayerDialogueInteraction.instance.ResetChecklist(); PlayerDialogueInteraction.instance.ResetChecklist();
PlayerDialogueInteraction.instance.ResetDialogue(); PlayerDialogueInteraction.instance.ResetDialogue();

View file

@ -0,0 +1,14 @@
using System;
using UnityEngine;
public class TableCollider : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("NPC"))
{
other.GetComponent<NpcMovementRework>().Stop();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ed21d83f6d63754aad737a383513a18
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: