public static class CardManager
{
private static DataToolbox m_toolBox;
private static Card[] m_cardDeck = new Card[3];
private static readonly List<GameObject> m_usedCards;
public static void DrawCards()
{
GameObject[] _deckSlots = Utilities.GetChildren(GameObject.Find("Deck")).ToArray();
for (int i = 0; i < 3; i++)
{
m_cardDeck[i].Instance(GDEDataManager.GetRandom<GDEFoodData>());
_deckSlots[i].GetComponentInChildren<Image>().sprite = m_cardDeck[i].GetFoodSprite;
_deckSlots[i].GetComponentInChildren<TextMeshProUGUI>().SetText(m_cardDeck[i].GetFoodName);
}
}
public class Card
{
private static string foodName;
private static string foodCode;
private static Sprite cardSprite;
public void Instance(GDEFoodData foodData)
{
foodName = foodData.filename;
foodCode = foodData.Key;
cardSprite = DataToolbox.Instance.GetFoodSprite(foodCode);
}
public string GetFoodName
{
get { return foodName; }
}
public string GetFoodCode
{
get { return foodCode; }
}
public Sprite GetFoodSprite
{
get { return cardSprite; }
}
}
}
嗨,我正在尝试在另一个类CardManager中创建一个类Card。 类卡具有一个构造函数,该构造函数可获取诸如name,sprite等变量。 到目前为止,我无法在DrawCards函数中使用它,我想在设置完变量后从中获取这些变量。 我觉得这是一个愚蠢的错误,但我不知道该如何解决。 非常感谢您的帮助。
谢谢你, 菲利波
更新:
好,我将其更改为此,现在可以使用了。我只是在构造函数和方法之间混淆。谢谢你的提示!
public class Card
{
public string foodName;
public string foodCode;
public Sprite cardSprite;
public Card (GDEFoodData foodData)
{
foodName = foodData.filename;
foodCode = foodData.Key;
cardSprite = DataToolbox.Instance.GetFoodSprite(foodCode);
}
}