【发布时间】:2015-07-06 07:53:56
【问题描述】:
我想在Start()和Update()函数之间等待2秒,我的代码:
void Start () {
r = GetComponent<RobotController>();
r.postEffectroPos(new Vector3(0.2f, 0.0f, 0.3f), 0.1f);
StartCoroutine(wait2Sec());
}
我的等待函数:
IEnumerator wait2Sec() {
yield return new WaitForSeconds(2.0f);
Debug.Log("Robot is moving to start position");
}
在更新()中:
if (controlRobot)
{
moveRobot();
movePlayerToRobot();
}
我想在开始时将我的机器人移动到设定位置,然后启用机器人的移动。问题是moveRobot() 获取了机器人的当前位置,并根据输入发布了一个调整位置的调用。
因此机器人不会在 Update() 函数中等待 Start() 函数完成 2 秒。
【问题讨论】:
标签: c# unity3d yield-return