My Fourth Game Design Blog Post –Handling The Scenes.

Today, I’m going to write about less programming bur more about meddling with the Unity itself. What I mean by that is that I will write how to manage scenes and buttons that load up scenes in Unity with the help of code.

Basically, managing scenes is simple but you can get somewhat lost if you don’t know what you are doing. When we create a scene and we save it as something we usually start doing something in it. A menu or the first lever of your game. If we create a menu, then we want buttons on it usually that on click start up different scene for example if I press play I the game would usually start. So, we must create scenes, one with game and one with the menu. First things first we must go to file, then to build settings where we click. After clicking a window opens where we can drag and drop our scenes from the assets folder.

ScenesBuild.png

(We are accessing Build Settings.)

You should watch the numbers on the left of your scenes in the builder. Those numbers will be used to called those specific scenes in your code.

If menu has a play button that you want to click and start the game with you should select it and in the inspector, add an on click function. After you do that you should assign the script where you will write the code to something in the menu scene, even camera works. There you assign the object that has the script.

Inpct.button.png

(Inspector of a button.)

The script must be able to manage the scenes, which you can do with a simple line of code that just fetches the unity scene manager to the script. Then all you must do is to make function which is for example “Play” and in it you can make it load scene with the number that this specific scene has on the left in the builder. The in inspector you select that function in on click and your button on click should load the scene you want.

I only had one problem with using scenes for now. One was that if I started pause menu that stopped time and clicked on restart button which load game scene from start the game would still be paused even after the restart. A simple fix was to make time to go from 0 to 1 after restart.

This the only way to manage scenes that I know of and can use. I haven’t really researched how to do it differently but I have a feeling that there might be different ways.

Cheers!

Leave a comment