その中に子オブジェクトを持つ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.
*/
}
}
}
どうすればよいですか?私はこの問題について自分自身を見つけることができませんでしたが、誰かが別の関連する質問へのリンクを持っている場合、私は喜んでそれを受け入れます。
public void UpdateResources()
{
for (int i = 0; i < GameObjects.Count; i++)
{
if (GameObjects[i] is Tile t)
{
t.X // <- read property
}
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加