Game Programming with Unity and C# by Casey Hardman
Author:Casey Hardman
Language: eng
Format: epub
ISBN: 9781484256565
Publisher: Apress
Scene Flow
Let’s examine a quick overview of how the loading of scenes is expected to flow for our game by the time we’re done with this.
The first scene in our build settings – the one that loads first – will be the main menu scene. We won’t have anything in this scene but a basic camera and an empty GameObject with a script that handles the main menu GUI.
This script will be called LevelSelectUI. It will call a little built-in method to instruct Unity that its GameObject should not be destroyed when a new scene is loaded. This way, the LevelSelectUI script can keep running after a level scene is opened.
Each level will have a scene all to itself. They’ll be numbered by their index in the Build Settings, and they’ll only show in the menu once we’ve added them to the build settings.
An instance of the Player prefab will be in each level scene, but the Player script will be disabled by default by unchecking the box beside its name in the Inspector, as we learned before. As well as this, the Camera GameObject inside the Player will be inactive – not just the Camera component, but the whole GameObject.
You can make this change through the Player prefab. First, make sure you’ve updated the Player prefab with any overrides that aren’t applied yet. Do this by selecting the Player in your Hierarchy, then clicking the Overrides dropdown in the header of the Inspector, and selecting “Apply All.”
Now open the Player prefab by double-clicking it in the Project window. Make the camera inactive by default, and disable the Player script by default. Now any level scenes you created (assuming you made one in the last chapter) will update to have the player at the initial state we desire.
Each level scene will have a Level View Camera on it, as we described in the previous chapter. This camera will be enabled by default, so when the LevelSelectUI loads the scene, we see the preview of the level, not the player’s view of the level. The player model will show in the level, but since the Player script is disabled, we won’t be able to move or act.
As long as we’re not in the main scene, our UI script will draw us a button we can press to play the game.
Once that button is pressed, we disable the Level View Camera, enable the Player script, and activate the player’s camera. Now the level is being played officially. We don’t need the UI anymore, so we destroy the GameObject holding the LevelSelectUI script.
When the player wins the level or uses the escape menu to quit (we’ll implement that in the next chapter), they’ll be brought back to the main scene again. Since we’ll be loading the main scene again, the same GameObject with the LevelSelectUI script on it will be there waiting for us again, so we can select our next level to play.
To set this up, we’ll start by cleaning any excess stuff out of the “main” scene we’ve had around since the start.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12555)
Hello! Python by Anthony Briggs(9904)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9785)
The Mikado Method by Ola Ellnestam Daniel Brolund(9769)
Dependency Injection in .NET by Mark Seemann(9329)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8282)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7756)
Grails in Action by Glen Smith Peter Ledbrook(7685)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7550)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7006)
Microservices with Go by Alexander Shuiskov(6774)
Practical Design Patterns for Java Developers by Miroslav Wengner(6683)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6629)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6399)
Angular Projects - Third Edition by Aristeidis Bampakos(6034)
The Art of Crafting User Stories by The Art of Crafting User Stories(5566)
NetSuite for Consultants - Second Edition by Peter Ries(5497)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5301)
Kotlin in Action by Dmitry Jemerov(5048)
