【发布时间】:2020-08-16 14:10:39
【问题描述】:
假设我有一个 GameObject 数组,其中包含子对象:
GameObjects = new List<GameObject>
{
new Tile(0, 0, new int[] { 1, 2, 3, 0 }),
new BuyTile(1, 0),
new BuyTile(0, 1),
new BuyTile(-1, 0),
new BuyTile(0, -1)
};
我想访问这个数组中 Tile 对象的属性。
public void UpdateResources()
{
for (int i = 0; i < GameObjects.Count; i++)
{
if (GameObjects[i] is Tile)
{
/* I want to read a property of the Tile here, and it's not in the abstract class
* GameObject.
*/
}
}
}
我该怎么做? 我自己找不到关于这个问题的任何信息,但如果有人有另一个相关问题的链接,我会很乐意接受。
【问题讨论】: