c# - 当我使用实例化语法 C# 按下播放按钮时,Unity 冻结
问题描述
每次我统一按下播放按钮时,它只是坐在那里什么都不做,我认为它与实例化语法有关,这是我的代码,这是我运行的唯一脚本。我试图简单地制作我的游戏对象的网格。如果有人知道为什么那会很棒,或者如果不是,也许您知道更好的方法。谢谢!!
using UnityEngine;
public class Script2 : MonoBehaviour
{
public GameObject Sprite;
void Start()
{
Generate();
}
public void Generate()
{
float width = Sprite.transform.lossyScale.x;
float height = Sprite.transform.lossyScale.y;
for (int y = 0; y <= 100; y += 10)
{
for (int x = 0; x <= 100; y += 10)
{
GameObject Square = Sprite;
Instantiate(Square, new Vector2(x * width, y * height), Quaternion.identity);
}
}
}
}
解决方案
你的 x 循环有一个错误,所以它陷入了无限循环。应该是 x+=10
for (int x = 0; x <= 100; x += 10)
{
GameObject Square = Sprite;
Instantiate(Square, new Vector2(x * width, y * height), Quaternion.identity);
}
推荐阅读
- javascript - 刷新页面时基于 react-js 的网页崩溃
- javascript - D3 JS:创建页面index.html来运行js项目
- matlab - 如何在 Matlab 中平滑阶梯状图
- javascript - npm 指挥官中的用法和参数有什么区别?
- python - tkinter.mainloop 函数的 n 参数是什么?
- redux - 如何使用 Immutabality 助手更新来修改 Redux 状态对象
- php - PHP函数根据属性随机输出图片
- kubernetes - 在 VSTS 中取消发布(取消部署)应用程序?
- c# - 如何使用 ADO.net 连接到 SQL Azure?
- javascript - 从 JQuery-UI 包含中排除元素