Book Image

Mastering Unity 2D game development

By : Simon Jackson
Book Image

Mastering Unity 2D game development

By: Simon Jackson

Overview of this book

Table of Contents (21 chapters)
Mastering Unity 2D Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Overview
Index

One last thing


Now that the player has left home, found some nasty goblins, and run away, it would be nice if he didn't encounter anymore until he next leaves home.

So using the additional flag PlayerReturningHome we set in the GameState class, we can set this in the battle manager when the player hits the button. We also then need to unset this when the player leaves home again. So, update the OnGUI method in the battle manager to set the PlayerReturningHome flag to true.

Then for the home scene, set the flag to false when the player leaves. This can be achieved by either editing an existing script in the home scene or adding a new one to change the flag state in the OnDestroy method mentioned earlier, or update the NavigationManager script to set the flag when the player travels home. It is your choice. In the sample code, I have added this to the NavigationManager script, as shown in the updated NavigateTo method here:

public static void NavigateTo(string destination)
{
if (destination ...