我试图在x轴上移动块,移动之间有延迟
public class setmove : MonoBehaviour
{
Transform trans
private void Start()
{
trans = GetComponet<Transform>();
}
private void Update()
{
if(trans.position.x != -15 { StartCoroutine(wait(20)); }
//this is here to make new block and destroy old one
if(trans.position.x <= -15 { GameObject .find("controller").GetComponet<set_make>().Start(); Destroy(this); }
private IEnumerator wait(int delay)
{
yield return new WaitForSecondsRealTime(delay);
trans.position = new vector3(trans.position.x-1, trans.position.y);
}
}
但没有延迟
我希望它等待,但间隔时间会缩短
1条答案
按热度按时间5us2dqdw1#
1.一个
float
几乎永远不会恰好是一个值(floating point inaccuracies)Update
每帧运行一次=〉只要满足条件,您将在每帧启动数百个并发协程。你可能应该只有一个单一的例行程序和