unity 协同

    void Update () {

      if(Input .GetKeyDown (KeyCode .W ))

        {

            StartCoroutine ("Test");

        }

    }

    IEnumerator Test()

    {

        while (Cube1 .position .x<6)

        {

            Cube1 .Translate (transform .right *3*Time .deltaTime );

            yield return null;

        }

        yield return new  WaitForSeconds(2);

        while (Cube2 .position .x<6)

        {

            Cube2 .Translate (transform .right *3*Time .deltaTime );

            yield return null;

        }

    }

 

你可能感兴趣的:(unity)