我正在学习Unity C#,我正在跟随Unity的2D roguelike教程,我们尝试实例化地板瓷砖,我按照视频中的步骤做了一遍(甚至连代码都复制了),但是在这一行代码上却出现了错误:
GameObject instance = Instantiate(toInstantiate, new Vector3(x, y, 0f),
Quaternion.identity) as GameObject;
具体来说,涉及到Instantiate(toInstantiate)
。
你能帮我吗?
using UnityEngine;
using System;
using System.Collections.Generic;
using Random = UnityEngine.Random;
public class BoardManager : MonoBehaviour
{
// Other class code omitted
void BoardSetup()
{
boardHolder = new GameObject("Board").transform;
for (int x = -1; x < columns + 1; x++)
{
for (int y = -1; y < rows + 1; y++)
{
GameObject toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)];
if (x == -1 || x == columns || y == -1 || y == rows)
toInstantiate = outerWallTiles[Random.Range(0, outerWallTiles.Length)];
GameObject instance = Instantiate(toInstantiate, new Vector3(x, y, 0f),
Quaternion.identity) as GameObject;
instance.transform.SetParent(boardHolder);
}
}
}
}
MonoBehaviour
? - Haytam