gpt4 book ai didi

c# - IEnumenator 出问题了

转载 作者:行者123 更新时间:2023-12-03 21:50:16 26 4
gpt4 key购买 nike

<分区>

我试图在 unity 中制作一个 c# 脚本,而脚本在第 61 行显示 'foodManager.foodEat(GameObject)': not all code paths return a value(标记为 **脚本末尾行的开头和结尾)关于 IEnumerator。这里有什么问题,我该如何解决?

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class FoodManager : MonoBehaviour
{

public bool[] isFull;
public GameObject[] slots;

public GameObject[] itemNames;
public GameObject[] itemImages;
public GameObject[] itemAmounts;
public GameObject foodObject;

public string[] foodNames;
public Sprite[] foodImages;
public Sprite[] foodHalfImages;

public GameObject foodPanel;
void Update()
{
for(int i = 0; i < 6; i++)
{
if (isFull[i] == true)
slots[i].SetActive(true);
if (isFull[i] == false)
slots[i].SetActive(false);
}
}

private void addItem(int max, string itemName, GameObject itemImage, int addingAmount, string foodName)
{
for (int j = 0; j < max; j++)
{
if (isFull[j] == true && itemNames[j].GetComponent<Text>().text == itemName)
itemAmounts[j].GetComponent<Text>().text = (int.Parse(itemAmounts[j].GetComponent<Text>().text) + addingAmount).ToString();
if (isFull[j] == false)
{
isFull[j] = true;
itemNames[j].GetComponent<Text>().text = itemName;
itemAmounts[j].GetComponent<Text>().text = addingAmount.ToString();
itemImages[j].GetComponent<Image>().sprite = foodImages[j];
break;
}
}
}

public void foodButtonsBehavior(int a)
{
if(a >= 0 && a < 6)
{
StartCoroutine(foodEat(slots[a]));
}
if(a == 6) //exit Button
foodPanel.SetActive(false);
}

**public IEnumerator foodEat(GameObject slot)**
{
foodPanel.SetActive(false);
}
}

我想使用 IEnumenator,因为我想将 WaitForSeconds() 添加到脚本中,但我还没有添加。请帮我解决这个问题,这很重要!

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com