Example #1
0
    private IEnumerator StateRoutine()
    {
        Vector2 pos = shooter.transform.position;

        failedWindow.SetActive(false);

        while (true)
        {
            stageText.text = stage + "\nLevel";
            ShotType type = (ShotType)(stage % 2);

            // initialize
            downPos = null;
            dir     = null;

            // Move shooter
            shooter.transform.position = pos;

            // Move and generate blocks
            yield return(blockManager.MoveAndGenerate((stage / 4) + 1, stage % 17 == 8, stage % 10 == 5));

            // Game failed.
            if (blockManager.MinPosition() < 1f)
            {
                break;
            }

            // Get direction
            blackSprite.gameObject.SetActive(type == ShotType.Black);
            whiteSprite.gameObject.SetActive(type == ShotType.White);

            hasControl = true;
            yield return(new WaitUntil(() => dir.HasValue));

            hasControl = false;

            // Shot and record floor
            floor.BeginHitRecord();

            yield return(shooter.Shot(dir.Value, damage, shotCount, type));

            yield return(new WaitUntil(() => ElectricBall.Actives.Count == 0));

            pos = (Vector3)floor.EndHitRecord() + new Vector3(0f, 0.2f, 0f);

            blackSprite.gameObject.SetActive(false);
            whiteSprite.gameObject.SetActive(false);

            yield return(new WaitForSeconds(1f));

            stage++;
            if (PlayerPrefs.GetInt("High Stage", 1) < stage)
            {
                PlayerPrefs.SetInt("High Stage", stage);
            }
        }

        // Fail.
        failedWindow.gameObject.SetActive(true);
        if (isTryAgain)
        {
            tryAgainButton.gameObject.SetActive(false);
        }
    }