コード例 #1
0
    private void CreateNextLevel(Vector3 oldPlatformCenter, Vector3 oldLeftGoal, int level)
    {
        float       nextCenterDistance   = Random.Range(minCenterDistance, maxCenterDistance);
        float       nextPlatformRotation = Random.Range(-maxRotation, maxRotation);
        Vector3     newPlatformCenter    = new Vector3(oldPlatformCenter.x - nextCenterDistance, oldPlatformCenter.y, oldPlatformCenter.z);
        Vector3     leftRightOffset      = new Vector3(0, 0, platform.transform.localScale.z / 2);
        GameObject  leftPlatform         = Instantiate(platform, newPlatformCenter - leftRightOffset, Quaternion.Euler(0, -nextPlatformRotation, 0));
        GameObject  rightPlatform        = Instantiate(platform, newPlatformCenter + leftRightOffset, Quaternion.Euler(0, 180.0f + nextPlatformRotation, 0));
        float       newGoalOffset        = Random.Range(-0.5f, 1.5f);
        GoalManager leftGoalManager      = leftPlatform.GetComponent <GoalManager>();
        GoalManager rightGoalManager     = rightPlatform.GetComponent <GoalManager>();

        leftGoalManager.MoveGoal(newGoalOffset);
        rightGoalManager.MoveGoal(newGoalOffset);
        float additionalBridgeLength = 10 / (level + 10) + 0.125f;
        float bridgeLength           = (oldLeftGoal - leftGoalManager.GetGoalPosition()).magnitude + additionalBridgeLength - 1;

        levels.Add(new Level(newPlatformCenter, leftGoalManager, rightGoalManager, bridgeLength, nextCenterDistance - platform.transform.localScale.x));
    }
コード例 #2
0
    private void CreateNextLevel(Vector3 oldPlatformCenter, Vector3 oldLeftGoal, int level)
    {
        float      nextCenterDistance   = Random.Range(minCenterDistance, maxCenterDistance);
        float      nextPlatformRotation = Random.Range(-maxRotation, maxRotation);
        Vector3    newPlatformCenter    = new Vector3(oldPlatformCenter.x - nextCenterDistance, oldPlatformCenter.y, oldPlatformCenter.z);
        Vector3    leftRightOffset      = new Vector3(0, 0, platform1.transform.localScale.z / 2);
        int        randomness           = Random.Range(0, 5);
        GameObject leftPlatform;

        switch (randomness)
        {
        case 1:
            leftPlatform = Instantiate(platform1, newPlatformCenter - leftRightOffset, Quaternion.Euler(0, -nextPlatformRotation, 0));
            break;

        case 2:
            leftPlatform = Instantiate(platform2, newPlatformCenter - leftRightOffset, Quaternion.Euler(0, -nextPlatformRotation, 0));
            break;

        case 3:
            leftPlatform = Instantiate(platform3, newPlatformCenter - leftRightOffset, Quaternion.Euler(0, -nextPlatformRotation, 0));
            break;

        case 4:
            leftPlatform = Instantiate(platform4, newPlatformCenter - leftRightOffset, Quaternion.Euler(0, -nextPlatformRotation, 0));
            break;

        default:
            leftPlatform = Instantiate(platform0, newPlatformCenter - leftRightOffset, Quaternion.Euler(0, -nextPlatformRotation, 0));
            break;
        }
        randomness = Random.Range(0, 5);
        GameObject rightPlatform;

        switch (randomness)
        {
        case 1:
            rightPlatform = Instantiate(platform1, newPlatformCenter + leftRightOffset, Quaternion.Euler(0, 180.0f + nextPlatformRotation, 0));
            break;

        case 2:
            rightPlatform = Instantiate(platform2, newPlatformCenter + leftRightOffset, Quaternion.Euler(0, 180.0f + nextPlatformRotation, 0));
            break;

        case 3:
            rightPlatform = Instantiate(platform3, newPlatformCenter + leftRightOffset, Quaternion.Euler(0, 180.0f + nextPlatformRotation, 0));
            break;

        case 4:
            rightPlatform = Instantiate(platform4, newPlatformCenter + leftRightOffset, Quaternion.Euler(0, 180.0f + nextPlatformRotation, 0));
            break;

        default:
            rightPlatform = Instantiate(platform0, newPlatformCenter + leftRightOffset, Quaternion.Euler(0, 180.0f + nextPlatformRotation, 0));
            break;
        }
        float       newGoalOffset    = Random.Range(-0.5f, 1.5f);
        GoalManager leftGoalManager  = leftPlatform.GetComponent <GoalManager>();
        GoalManager rightGoalManager = rightPlatform.GetComponent <GoalManager>();

        leftGoalManager.MoveGoal(newGoalOffset);
        rightGoalManager.MoveGoal(newGoalOffset);
        float additionalBridgeLength = 1.0f / (level + 6.0f) * 6.0f - 0.3f;
        float bridgeLength           = (oldLeftGoal - leftGoalManager.GetGoalPosition()).magnitude + additionalBridgeLength - 1;

        levels.Add(new Level(newPlatformCenter, leftGoalManager, rightGoalManager, bridgeLength, nextCenterDistance - platform1.transform.localScale.x));
    }