Snow Boarder | Where I'm at after tuning

I’ve been going through the section, and after tuning I introduced a leveling system on top of everything else with a level indicator that updates as you enter a new level. Of course completely independent of the number of scenes actually in the game.

I did this by modifying the LoadScene method in the FinishLine script:

void LoadScene()

    {
        // Get the actual number of scenes from the build settings
        int sceneCount = SceneManager.sceneCountInBuildSettings;

        Debug.Log(sceneCount + " Scenes");    // just verifying :)

        level = SceneManager.GetActiveScene();

        // Since buildIndex is 0 based, I want to check if the build index (0, 1, 
        // 2, etc.) is less than the scene count, which is 1 based, so I subtract 
        // 1 from the scene count.

        if(level.buildIndex < (sceneCount - 1)) 
        {
            nextLevel = level.buildIndex+1;
        }
        else
        {
            nextLevel = 0;
        }
        SceneManager.LoadScene(nextLevel);
    }

To display the Level indicator, I added a canvas with a TextMesh Pro object on it, and created a Level script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;

public class Level : MonoBehaviour

{

    public TMP_Text levelIndicator;

    void Start()

    {
        Scene currentScene = SceneManager.GetActiveScene();

        int currentLevel = currentScene.buildIndex + 1;
        levelIndicator.text = "Level: " + currentLevel;
    }
}

Here’s a screenshot of level 2, where I added an extra indicator of it being a new level by changing the SpriteShape color property.

I noticed the Level indicator was behind the clouds, but I kinda like it… So I’m leaving it there (for now at least). I might change that if I add scoring or a timer in the future.

1 Like

Privacy & Terms