我知道,如果while循环无法结束,Unity就会崩溃,但是我不知道该如何用另一种方式来实现。我的想法是制作一个主菜单,在该菜单中,相机会持续永久地稍微向上,向下,向左或向右移动。摄像机路径的方式可以是随机的,也可以是特定的路径。我只是不知道如何随机设置路径。
我写的代码:
public class smooth_menu_cam : MonoBehaviour
{
public GameObject one;
public GameObject two;
public GameObject three;
public GameObject four;
public GameObject five;
public GameObject Menu;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Move();
}
void Move()
{
if (transform.position == Menu.transform.position)
{
int i = 0;
while (transform.rotation.y == 0)
{
transform.localPosition = Vector3.MoveTowards(transform.position, one.transform.position, 1f * Time.deltaTime);
i++;
}
}
}
}
我应该改变什么?我还使用了“ Vector3.slerp”,但它也没有解决。我是C#编程的新手。
谢谢您的帮助。