AJ Esguerra
Rena Escora
Jen Carlo Napoto
BS-EMC 2A

Activity 8: Level Unlock

This time I made a Level Unlock feature using button function and scene manager to control the sequence of scenes in the game. Like on the previous blog, we make a button for the Main Menu scene in order for us to move to different scenes. But because we wanted a game unlocked feature, we have to use a different script and a Main Menu layout. Let's start by adding our assets. Sprites needed for Player, Enemy, Obstacles, and Background image. I also imported some scripts from the previous creations. So I'm just gonna give you the new scripts to add it to the game.





Main Mene Script:




Level Control Script:




Portal Script 
(Or next YouWin Script for You Win Text):


Skull Script 
(for You Lose Text):


By now, we can start building the Main Menu Scene.

Let's start by making a UI - text for out Title Text and Level Select text. Then name your game, and change the font and its size. Then make a UI - Button for Level 1, Level 2, and Level 3. Arrange them to your preferred layout. 


Now let's create a gameObject named MainMenuControl, and then insert MainMenuScript on it. Then on inspector - MainMenuScript drag and drop the specific buttons(objects) needed.

Now click Level 1 button and down to inspector - On Click Method put of MainMenuControl Object and on function select the MainMenuControlScript - levelToLoad (), then set it to one(1) to load scene 1 as assigned in Build settings. Do the same steps to each button (change the value base on Build Settings).

Last thing for the MainMenu scene is the Reset Button. So create UI - Button for Reset then put on the On Click Method the Main Menu Control Object then on function, select MainMenuController Script and select resetPlayerPrefs. Once done, then you may decorate and change the button by applying sprites until it looks decent.

We can start making the Level Scenes. So on Assets - Scenes create a Scene and name it Level 1. Now lets build the scene by applying our assets. Put a skull, player, and portal(finish) objects on scene, on skull object put the Skull Script, then on Portal object put the Portal Script and also put a Collider2D component set on trigger on each one. Assign a PlayerMovement script for our player object, then try moving it and adjusting the speed and setting RigidBody 2D and Collider2D component. 

Moving on, we want to make a Text object for the Level Number and a text where the player is notified if they Win or Lose in the game. Let's first create a GameOverText and a YouWinText on canvas. Edit the text and adjust its location and size. Once done then create a gameObject named LevelController then insert LevelController Script on it which will control th GameOverText if the player collides to the Skull object and YouWinText if the player collides to the portal object.




Lastly, create a SceneLoader Object and put the SceneLoader Script to it. But its only optional if you are going to put a back button that redirects to the Main Menu.



That said, let us make a Prefab of each part of the scene by dragging them to Prefab folder which allows us to reuse the same Prefab Layout like what we did to Level 1.


Now Lets create Level 2 and Level 3 scenes then to each of them - drag all the prefabs from Level 1. by now the three levels are similarly look alike because we hadn't added more sprites or even a complete obstacle maze for each level.


Back to Level 1 scene. Arrange your preferred sprites and put then on canvas as Image then assign a sprite(depends on what object you want it to be represented). Build your obstacles and always put a Collider2D component to it. Once you had made it as a map, then place more enemy objects by duplicating the skull object(or your enemy object) put a script that will make it move from point A(default position to axis) to point B. For that, we need a script for its movement.


Move Script(for Skull Object Movement or Enemy Object):


You may change the speed of the object by editing the value of ticks in the script, the higher the number the slower the object.

By now go back to our MainMenu Scene and Play it. Remember that you should assign also the scenes accordingly to our Build Settings. Then if you still want to add some levels or make the game more appealing, it's up to you.

See for yourself. . .

Level 1

Level 2
Level 3


That's all Thank you!

Comments