可以通过以下代码在 Unity 中生成一个 10x10 的 GameObject 网格:

public GameObject prefab;
public int width = 10;
public int height = 10;

void Start()
{
    for(int x = 0; x < width; x++)
    {
        for(int y = 0; y < height; y++)
        {
            Instantiate(prefab, new Vector3(x, y, 0), Quaternion.identity);
        }
    }
}

将上述代码添加到一个游戏对象上,将预制体拖到 'prefab' 变量中,然后运行游戏即可生成一个 10x10 的 GameObject 网格。

Unity: 生成 10x10 网格的 GameObject

原文地址: https://www.cveoy.top/t/topic/oedQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录