Exemple #1
0
    IEnumerator Go()
    {
        yield return(new WaitForSeconds(StartTime));

        while (true)
        {
            if (type == Type.AllRandom)
            {
                CurV = rigidbody2.velocity = Statics.FaceVec(Quaternion.Euler(0, 0, Random.Range(0, 360))) * Random.Range(A_dis_min, A_dis_max) / RunTime;
                if (Rotate)
                {
                    transform.rotation = Quaternion.Euler(0, 0, RotateDeg + Mathf.Rad2Deg * Mathf.Atan2(CurV.y, CurV.x));
                }
                RoundTimes++;
                yield return(new WaitForSeconds(RunTime));

                if (RunAfterStep)
                {
                    RunAfterStep.Fun();
                }
                CurV = rigidbody2.velocity = Vector2.zero;
                yield return(new WaitForSeconds(StopTime));
            }
            else
            {
                int next;
                if (type == Type.Random)
                {
                    next = Random.Range(0, maxSize);
                }
                else
                {
                    next = now + 1;
                    if (next == maxSize)
                    {
                        next = 0;
                        RoundTimes++;
                        if (RunAfterRound)
                        {
                            RunAfterRound.Fun();
                        }
                    }
                }
                if (KeyPoints[next] && KeyPoints[now])
                {
                    CurV = rigidbody2.velocity = (KeyPoints[next].position - KeyPoints[now].position) / RunTime;
                }
                if (Rotate)
                {
                    transform.rotation = Quaternion.Euler(0, 0, RotateDeg + Mathf.Rad2Deg * Mathf.Atan2(CurV.y, CurV.x));
                }
                yield return(new WaitForSeconds(RunTime));

                if (RunAfterStep)
                {
                    RunAfterStep.Fun();
                }
                CurV = rigidbody2.velocity = Vector2.zero;
                yield return(new WaitForSeconds(StopTime));

                now = next;
            }
        }
    }