In this step, you create a StartApp object to create a timer that tells the app how long the splash scene should be displayed before switching to the main scene.
For other steps in this exercise, see Exercise 3: Connect Two Scenes.
To create the StartApp object:
- From the Property view, open the /Assets/Workshop/Scenes/Splash.unity file.
- From the Hierarchy view, select Create > Create Empty.
- From the Inspector view, change the name of the object from GameObject to StartApp and press Enter to save the change. You will use this empty object to create a timer that tells the app how long the splash scene should be displayed before switching to the main scene.
- Click the Add Component button and select Scripts > Start App. This will add the Start App script as a component of the StartApp game object you created.
- From the Start App component, double-click the StartApp script to open the file in MonoDevelop, Unity's code editor, where you can further inspect the script.
- From MonoDevelop, review the StartApp script. You will notice that several variables are defined at the top of the script file. The public variables in the script are customizable in the Unity UI, while the private variables are not. This is useful when working on a project with several people. A developer can set the variables in the code, allowing designers to tweak the properties as needed within Unity. You will also notice that this script file, along with all of the other provided scripts for app, have been thoroughly commented, giving you details on how each element contributes to the app.
- Close MonoDevelop and return to Unity.
- From the Unity menu, select File > Build Settings.
- From the Project view, drag the /Assets/Workshop/Scenes/Main.unity file into the Build Settings window. Each scene in your app is given an index number. Scenes with an index value of 0 are displayed first, scenes with an index of 1 are displayed second, and so on. In this app, the first scene that will be displayed is the splash scene.
- Close the Build Settings window.
- Review the Start App component in the Inspector view. This script sets the duration of the splash scene to 2.5 seconds and tells the app to switch to the scene with an index value of 1 - the main scene.
- Extend the duration of the splash scene by changing the MSplash Duration property to 5 seconds.
- Save the scene.