如何在随机速度范围内移动角色?

时间:2017-09-07 21:50:40

标签: c# unity3d unity5

现在所有对象都使用moveSpeed全局变量以相同的速度移动。

private void MoveToNextFormation()
    {
        float step = moveSpeed * Time.deltaTime;
        for (int i = 0; i < squadMembers.Count; i++)
        {
            squadMembers[i].transform.LookAt(newpos[i]);
            if (randomSpeed == true)
            {
                step = Random.Range(3, 50) * Time.deltaTime;
            }
            squadMembers[i].transform.position =
            Vector3.MoveTowards(squadMembers[i].transform.position, newpos[i], step);
            if (Vector3.Distance(squadMembers[i].transform.position, newpos[i]) < threshold)
            {
                if (squareFormation == true)
                {
                    Vector3 degrees = new Vector3(0, -90f, 0);
                    Quaternion quaternion = Quaternion.Euler(degrees);
                    squadMembers[i].transform.rotation = Quaternion.Slerp(squadMembers[i].transform.rotation, quaternion, rotateSpeed * Time.deltaTime);
                }
                else
                {
                    squadMembers[i].transform.rotation = Quaternion.Slerp(squadMembers[i].transform.rotation, qua[i], rotateSpeed * Time.deltaTime);
                }
            }
        }
    } 

我尝试添加此部分:

if (randomSpeed == true)
            {
                step = Random.Range(3, 50) * Time.deltaTime;
            }

但它不影响速度运动。 我希望每个角色都以另一种速度移动。

0 个答案:

没有答案