コード例 #1
0
    //the actual flow of the game, yielding to other coroutines;
    IEnumerator ExecuteGameFlow()
    {
        //setting initial data;
        StageData currentStage        = firstStage;
        bool      isThereAnotherStage = true;

        //setting player position in case it's somewhere else;
        player.movementPattern = currentStage.GetComponent <SplineData> ();
        player.SetTransformAt(0);

        //game loop;
        while (isThereAnotherStage)
        {
            //starts on 1st stage;
            currentStage.SpawnAllTargets();
            EnableInput(true);
            //wait for action message;
            if (currentStage.spawners.Count > 0)
            {
                yield return(StartCoroutine(StartStageAction()));
            }
            //now wait till all targets are dead;
            yield return(StartCoroutine(currentStage.CheckIfStageClear()));

            //TODO:stop if player dead;
            //after killing all sets camera movement;
            player.movementPattern = currentStage.GetComponent <SplineData> ();
            //disable input while moving;
            EnableInput(false);
            //check if there is another stage!
            if (player.movementPattern.fixedFinalPosition == null)
            {
                isThereAnotherStage = false;
                EndLevel(true);
            }
            else
            {
                //coroutine to move the camera to the next stage;
                yield return(StartCoroutine(player.MoveTransform()));

                //after moving switch to new stage;
                currentStage = player.movementPattern.fixedFinalPosition.GetComponent <StageData> ();
            }
        }
        yield return(null);
    }