In order to connect our scenes together, we need player input to trigger an event. We do have an event setup for when the player clicks on the monster in the Map scene. However, we also want the player to move from the Map/Catch scene to the Inventory scene and back. In order to do this, we will add some UI buttons to each of the scenes.
Since we already have the Inventory scene already open, let's begin by adding the new button to that scene:
InventoryBag
object in the Hierarchy window and select UI | Button from the context menu. This will add a button just below the Panel
. Expand the Button
object and then select the child Text
object and press delete to remove it.Button
object and rename it ExitButton
in the Inspector window.button_set11_b
from the dialog.ExitButton
is shown in the following screenshot:
ExitButton component configuration
The ExitButton
we just added is for closing the Inventory scene and returning to the scene that opened it. Before we get the Map and Catch scenes, we first need to transfer our services to the Game scene and take care of some minor updates. Perform the instructions to update the Game scene:
Assets
folder in the Project window, drag the Game scene to the Hierarchy window.Services
object from the Inventory scene to the Game scene. This will be the new permanent home for the Services
object. Rename the Services
to _Services
in the Inspector window. Again, we use the _
to denote objects that are not to be destroyed._GameManager
object in the Hierarchy window, and update the Game Manager script scene names, as shown in the screenshot:
Game Manager Scene names updated
Next, we will add a new button to access the Inventory scene on the Map scene. Follow the instructions to add the new button:
Assets
folder in the Project
window. This will close the Game scene, and when prompted, ensure that you save the changes.MapScene
object in the Hierarchy window, and right-click (press Ctrl and click, on a Mac) to open the context menu. From the menu, select UI | Button, to add a new button.
HomeButton
. Set the Rect Transform | Anchor Presets to bottom-center while holding the position/pivot keys. Change the Rect Transform | Width/Height to 80
and the Pos Y to 10
. Then, change Image | Source Image to button_set06_b
by clicking on the bullseye icon and selecting the sprite for the Select Sprite dialog.HomeButton
script from the Assets/FoodyGo/Scripts/UI
folder in the Project window and drop it onto the HomeButton
object in the Hierarchy window.HomeButton
object from the Hierarchy window to the Assets/FoodyGo/Prefabs
folder in the Project window to make it a new prefab.Finally, the last scene we need to do is the Catch scene, which will make our round trip complete. Perform the following directions to add the HomeButton
to the scene:
Assets
folder of the Project window. This will close the Map scene, and when prompted, ensure that you save the changes.CatchScene
object in the Hierarchy window. From the Assets/FoodyGo/Prefabs
folder in the Project window, drag the HomeButton
prefab and drop it onto the Catch_UI
object. You will now see the HomeButton
drawn over top of the CatchBall
in the scene.HomeButton
, and in the Inspector window, change the Rect Transform | Anchor Presets to top-right while, of course, holding the pivot/position keys. Then, change the Pos X and Pos Y to -10
.Now, with the scene transition buttons added, all the scripts updated, and everything else set, it is time to bring everything together and run the game.
18.224.33.107