每次我统一按下播放按钮时,它只是坐在那里什么都不做,我认为这与实例化语法有关。这是我的代码,这是我运行的唯一脚本。我试图只是简单地为我的GameObject制作网格。如果有人知道为什么这样很棒,或者如果不是,那么您知道一种更好的方法。谢谢!
14.x
答案 0 :(得分:1)
您的x循环有错误,因此遇到了无限循环。 应该是x + = 10
for (int x = 0; x <= 100; x += 10)
{
GameObject Square = Sprite;
Instantiate(Square, new Vector2(x * width, y * height), Quaternion.identity);
}
答案 1 :(得分:0)
我拥有的最佳解决方案是在创建预制网格时使用的方法
using UnityEngine;
public class Class1 : MonoBehaviour
{
public GameObject Prefab;
private void Start ()
{
Generate ();
}
public void Generate ()
{
float width = Prefab.transform.lossyScale.x;
float height = Prefab.transform.lossyScale.y;
for ( int y = 0; y < 100; y++ )
{
for ( int x = 0; x < 100; x++ )
{
Vector3 position = new Vector3 ( x * width, y * height );
Instantiate<GameObject> ( Prefab, position, Quaternion.identity );
}
}
}
}