Ejemplo n.º 1
0
    IEnumerator FinalMovement()
    {
        // Wait a tiny bit for "shooting while standing" effect
        yield return(new WaitForSeconds(0.25f));

        float i = 0f;
        // How long to move for
        float time = 1f;
        float rate = 1.0f / time;

        // How far to move in that time
        // To calculate rate, get change in position (WidestPt-ZeroPt = Displacement)
        float zoomRate = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x;

        zoomRate -= Camera.main.ScreenToWorldPoint(Vector3.zero).x;
        while (i < 1.0)
        {
            yield return(new WaitForEndOfFrame());

            // If not active, exit out of this whole shenanigan!
            if (!active)
            {
                i = 5;
            }

            i = i + (Time.deltaTime * rate);

            // Zoom off the screen
            Vector2 pos = transform.position;
            pos.x += -zoomRate * Time.deltaTime;
            transform.position = pos;
        }

        // Finally "destroy" self and return to pool
        spawnController.KillSpawn();
    }