Fun with learning level systems!

Hello!

I’m back with a bit of my noobish approach to a level system! I have successfully implemented something that is working at least hah šŸ™‚

Currently what I have implemented is:

Start of level canvas // end of level canvas

This is just a sprite that is spread across the screen. This is a canvas object that is configured like this in the inspector and this in the heiarchy(Don’t mind me, I havne’t named everything ;)), and like this in the inspector .

This setup above is placed in each level. This is manually configured in terms of the text that shows for the level name. The rest is determined on load programatically. This canvas is enabled on start, and the script I have attached slowly fades out the canvas and eventually diables it. This start canvas also freezes time, and enables the “Ready, Set, Go” countdown. This also starts the timer for each level!

Dynamic text on each start/end screen (as well as overworld sign)

I display the best time, and if you earned the bonus on the sign infront of each level.

This information is the same that is displayed on the start and end screens. It is all loaded programatically through the level system I implemented. Basically how it works is I have a Level Manager, that contains multiple Level classes. Each Level class contains the level specific information like best time, par time ect.

[System.Serializable]
public static class LevelDataManager {

   public static level level1 = new level("ForestLevel1", 1, 45.00, 0.00, 50, false, false, false);
   public static level level2 = new level("ForestLevel2", 2, 125.00, 0.00, 100, false, false, false);
   public static level level3 = new level("ForestLevel3", 3, 150.00, 0.00, 100, false, false, false);


    [System.Serializable]
    public class level
    {
        public string levelName;
        public int levelNumber;
        public double parTime;
        public double bestTime;
        public int experienceWorth;
        public bool bonusGranted;
        public bool lpBonusCollected;
        public bool levelCompleted;

        public level(string in_levelName, int in_levelNumber, double in_parTime, double in_bestTime, int in_experienceWorth, bool in_bonusGranted, bool in_lpBonusCollected, bool in_levelCompleted)
        {
            this.levelName = in_levelName;
            this.levelNumber = in_levelNumber;
            this.parTime = in_parTime;
            this.bestTime = in_bestTime;
            this.experienceWorth = in_experienceWorth;
            this.bonusGranted = in_bonusGranted;
            this.lpBonusCollected = in_lpBonusCollected;
            this.levelCompleted = in_levelCompleted;
        }

 }

So above I just pre-create each level. This is created everytime the game loads up, and is also replaced if the player Continues their game.

The saving and loading I will handle in a later post. But basically how it works is I store a list of all the games levels in my “DataManager” class. And this list gets saved, and loaded accordingly. This keeps the values of your best time as well, so it persists between play sessions.

Some fun expanding my knowledge of UI!

First off…Unity’s Animator works with UI components….MIND BLOWN.

This was pretty fun to play around with. Now I need to go back to my original UI design and change a few things! Adding that little animation makes it look so much more alive I think. It’s as basic as just selecing the object with your worldspace canvas, and creating an animation. Move the canvas only, and create your animation! Through script you can control it like any other animation:

 void OnTriggerEnter(Collider collider)
    {

        if (collider.gameObject.tag == "player")
        {
            Debug.Log("Play DoorPost Enable Animation");
            gameObject.GetComponent<Animator>().SetBool("openInfo", true); 
            //gameObject.GetComponent<Animator>().Play("PostInfoEnable");

        }

    }

Spawning/Despawing collectables

So handling the spawning and de-spawning of one time only collectables has been pretty easy. Basically I have a variable in my level class that determines the first type of collectable, the LP bonus. This is saved and checked on load/collect. If the player has collected it, it is destroyed on load.

    levelToUse = DataManager.levelList[levelNumber];
    if (levelToUse.lpBonusCollected)
    {
        Destroy(gameObject);
    }

If needed I can simply add more variables to my level class as my game expands. I can even nest a list for all of the coins in each level if I want to go that far!

Title Screen

Image

Adding this in actually required me to overhaul a good chunk of my code. I’m glad I decided to start working towards a three level early alpha release. I decided to make the title screen and its a good thing. It changed the way that I handle the saving and loading my game, as well as moving all of my “Dont destroy on load” objects from the old tutorial scene to the new title scene.

This made me have to re-write a few references in my successive screen to objcets that I had to move. It caused me to have to re-visit a bit of my level loading code to ensure things were saving/loading correctly.

I made this with existing assets from my game. If you watched the video, it is actually animated so it looks a bit better than just a picture :). This was another stab at doing some UI work. Currently this is just a basic canvas that has three buttons. Options is not configured yet, as looking into adjusting resolution/controls/sound and all that stuff is something I have NO idea how to do! The text is actually created using Inkscape and ported into Unity as sprites! Found it actually worked really well šŸ™‚

Start New simply just loads the next level of the game fresh start. Pretty basic here, not a whole lot to explain.

Continue, this checks the unity local persistance directory for a file, if found it loads the game accordingly.

Questions, comments, feedback anything is cool šŸ™‚

Leave a comment