伙计们,当我先给它贴上披萨标签的食物时,我怎么能阻止它呢?
请帮帮我,我找不到路。我该怎么办?顺便说一句,我是新来的,很抱歉发帖不好:/
我在做比萨饼店的游戏。所以顾客会坐着等披萨,如果我们给披萨贴标签,服务员就应该开始,然后开始吃比萨饼,但我的服务生比萨饼并没有停止。
IEnumerator EAT, PAY, WAIT;
private void Start()
{
EAT = EatPizza();
WAIT = WaitForPizza();
PAY = WaitForTheCase();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pizza"))
{
canEat = true;
}
if (other.gameObject.CompareTag("Out"))
{
Destroy(this.gameObject);
}
}
void Update()
{
if (isEating)
{
if (Vector3.Distance(transform.position, agent.destination) <= 1f)
{
anim.SetTrigger("sit");
isEating = false;
}
}
if (!isEating && !isPaying && !isOut && !canEat)
{
StartCoroutine(WaitForPizza());
}
if (!isEating && !isPaying && !isOut && canEat)
{
StopCoroutine(WAIT);
StartCoroutine(EatPizza());
}
if (isPaying)
{
isEating = false;
anim.SetTrigger("walk");
agent.destination = checkoutTarget.position;
if (Vector3.Distance(transform.position, agent.destination) <= 1f)
{
anim.SetTrigger("wait");
if (ifCashier)
{
//throw money
isPaying = false;
isOut = true;
}
if (!ifCashier)
{
StartCoroutine(WaitForTheCase());
}
}
}
if (isOut)
{
anim.SetTrigger("walk");
isEating = false;
isPaying = false;
agent.destination = outTarget.position;
}
if (canEat)
{
StopCoroutine(WAIT);
}
}
IEnumerator WaitForTheCase()
{
anim.SetTrigger("wait");
yield return new WaitForSeconds(randomFloatWait);
angry.SetActive(true);
isEating = false;
isPaying = false;
isOut = true;
}
IEnumerator EatPizza()
{
angry.SetActive(false);
StopCoroutine(WaitForPizza());
happy.SetActive(true);
yield return new WaitForSeconds(randomFloatWait);
happy.SetActive(false);
isEating = false;
isPaying = true;
isOut = false;
}
IEnumerator WaitForPizza()
{
while (!canEat)
{
yield return new WaitForSeconds(randomFloatWait);
angry.SetActive(true);
isEating = false;
isPaying = false;
isOut = true;
}
}发布于 2022-03-30 10:57:11
首先,将WAIT定义为Coroutine,然后当您想要开始等待时使用WAIT = StartCoroutine(WaitForPizza());,当您想要完成它时使用StopCoroutine(WAIT);。
https://stackoverflow.com/questions/71409445
复制相似问题