为什么不从检查员出现新创建的实例?
用例:创建卡并将其添加到卡列表中。
我正在创建卡的新实例,并将其添加到卡列表中。
[SerializeField] private List<Card> _deckCards = new List<Card>();
public void LoadDeck()
{
Card newCard = new Card();
newCard.UpdateCardState(CardState.DECK);
_deckCards.Add(newCard);
}
但是,甲板卡列表将添加的卡显示为Unity Inspector中的无。
indepcted 屏幕截图
是否有这样的原因?谢谢!
Use case: Creating a card and adding it on a list of cards.
I'm creating a new instance of a Card and adding it on a list of cards.
[SerializeField] private List<Card> _deckCards = new List<Card>();
public void LoadDeck()
{
Card newCard = new Card();
newCard.UpdateCardState(CardState.DECK);
_deckCards.Add(newCard);
}
However the deckCards list is displaying the added cards as none from the Unity inspector.
Is there a reason why this happens? thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在解决了。事实证明,卡是从Monobehavior继承的类。
为了解决这个问题,我必须删除单obehavior,然后从卡类的顶部添加[System.Serializable]。
Solved now. Turns out, Card is a class that inherits from Monobehavior.
To fix this, I had to remove Monobehavior and add [System.Serializable] from the top of the Card class.