Example #1
0
    /// <summary>
    /// ランダムで花輪を生成してステージ作成
    /// </summary>
    /// <returns></returns>
    private IEnumerator CreateRandomStage()
    {
        float flowerHeight = goal.position.y;
        int   count        = 0;

        Debug.Log("初期の花輪のスタート位置 : " + flowerHeight);
        while (flowerHeight <= player.transform.position.y - 15)
        {
            flowerHeight += Random.Range(5.0f, 10.0f);
            Debug.Log("現在の花輪の生成位置 : " + flowerHeight);
            FlowerCircle flowerCircle = Instantiate(flowerCirclePrefab, new Vector3(Random.Range(limitLeftBottom.position.x, limitRightTop.position.x), flowerHeight, Random.Range(limitLeftBottom.position.z, limitRightTop.position.z)), Quaternion.identity);
            flowerCircle.SetUpMovingFlowerCircle(Random.Range(0, 100) <= movingFlowerCirclePercent, Random.Range(0, 100) <= scalingFlowerCirclePercent);
            count++;
            Debug.Log("花輪の合計生成数 : " + count);
            yield return(null);
        }

        Debug.Log("ランダムステージ完成");
    }
Example #2
0
    /// <summary>
    /// ランダムで花輪を生成してステージ作成
    /// </summary>
    private IEnumerator CreateRandomStage()
    {
        // 花輪の高さのスタート位置
        float flowerHeight = goal.position.y;
        // 障害物の高さのスタート位置
        float obstacleflowerHeight = goal.position.y;
        // アイテムの高さのスタート位置
        float itemTrampolineHeight = goal.position.y;


        // 花輪と障害物、アイテムを生成した数
        int count = 0;

        Debug.Log("初期の花輪のスタート位置 : " + flowerHeight);
        Debug.Log("初期の障害物のスタート位置 : " + obstacleflowerHeight);
        Debug.Log("初期のアイテムのスタート位置 : " + itemTrampolineHeight);


        // 花輪の高さがキャラの位置に到達するまで、ループ処理を行って花輪を生成する。キャラの位置に到達したらループを終了する
        while (flowerHeight <= player.transform.position.y)
        {
            // 花輪の高さを加算(float 型の Random.Range メソッドは 10.0f を含む)
            flowerHeight += Random.Range(5.0f, 10.0f);

            Debug.Log("現在の花輪の生成位置 : " + flowerHeight);

            // 花輪の位置を設定して生成
            FlowerCircle flowerCircle = Instantiate(flowerCirclePrefab, new Vector3(Random.Range(limitLeftBottom.position.x, limitRightTop.position.x), flowerHeight, Random.Range(limitLeftBottom.position.z, limitRightTop.position.z)), Quaternion.identity);

            // 花輪の初期設定を呼び出す。引数には評価後の戻り値を利用する。このとき、移動するかどうか、大きさを変えるかどうかの情報を引数として渡す
            flowerCircle.SetUpMovingFlowerCircle(Random.Range(0, 100) <= movingFlowerCirclePercent, Random.Range(0, 100) <= scalingFlowerCirclePercent);

            // 花輪の生成数を加算
            count++;

            Debug.Log("花輪の合計生成数 : " + count);

            // 1フレームだけ中断。  ※ この処理を入れないと無限ループしてUnityがフリーズします。
            yield return(null);
        }

        // 障害物の高さがキャラの位置に到達するまで、ループ処理を行って障害物を生成する。キャラの位置に到達したらループを終了する
        while (obstacleflowerHeight <= player.transform.position.y)
        {
            // 花輪の高さを加算(float 型の Random.Range メソッドは 10.0f を含む)
            obstacleflowerHeight += Random.Range(5.0f, 10.0f);

            Debug.Log("現在の障害物の生成位置 : " + obstacleflowerHeight);

            // 花輪の位置を設定して生成
            ObstacleFlower obstacleFlower = Instantiate(obstacleFlowerPrefab, new Vector3(Random.Range(limitLeftBottom.position.x, limitRightTop.position.x), obstacleflowerHeight, Random.Range(limitLeftBottom.position.z, limitRightTop.position.z)), Quaternion.identity);

            // 花輪の初期設定を呼び出す。引数には評価後の戻り値を利用する。このとき、移動するかどうか、大きさを変えるかどうかの情報を引数として渡す
            obstacleFlower.SetUpMovingObstacleFlower(Random.Range(0, 100) <= movingObstacleFlowerPercent, Random.Range(0, 100) <= scalingObstacleFlowerPercent);

            // 花輪の生成数を加算
            count++;

            Debug.Log("障害物の合計生成数 : " + count);

            // 1フレームだけ中断。  ※ この処理を入れないと無限ループしてUnityがフリーズします。
            yield return(null);
        }

        // 障害物の高さがキャラの位置に到達するまで、ループ処理を行って障害物を生成する。キャラの位置に到達したらループを終了する
        while (itemTrampolineHeight <= player.transform.position.y)
        {
            // 花輪の高さを加算(float 型の Random.Range メソッドは 10.0f を含む)
            itemTrampolineHeight += Random.Range(5.0f, 10.0f);

            Debug.Log("現在のアイテムの生成位置 : " + itemTrampolineHeight);

            // 花輪の位置を設定して生成
            ItemTrampoline itemTrampoline = Instantiate(itemTrampolinePrefab, new Vector3(Random.Range(limitLeftBottom.position.x, limitRightTop.position.x), itemTrampolineHeight, Random.Range(limitLeftBottom.position.z, limitRightTop.position.z)), Quaternion.identity);

            // 花輪の初期設定を呼び出す。引数には評価後の戻り値を利用する。このとき、移動するかどうか、大きさを変えるかどうかの情報を引数として渡す
            itemTrampoline.SetUpMovingTrampoline(Random.Range(0, 100) <= movingItemTrampolinePercent, Random.Range(0, 100) <= scalingItemTrampolinePercent);

            // 花輪の生成数を加算
            count++;

            Debug.Log("アイテムの合計生成数 : " + count);

            // 1フレームだけ中断。  ※ この処理を入れないと無限ループしてUnityがフリーズします。
            yield return(null);
        }

        Debug.Log("ランダムステージ完成");
    }