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

The missing random piece


We have our battle scene up and running, and when the player runs away he/she will still be at the place on the map where the battle occurred. Wouldn't it be nice to also enter the battle scene? So let's add that.

To keep things simple (you can always extend it later), we will just use a simple probability to work out whether the player is likely to enter a battle while travelling. If a battle is going to occur, we just figure out then where on the player's journey the battle will take place. This way it looks random and catches the player off guard when it happens (if it does, there's always a chance it won't).

Note

Alternatively, you could place empty game objects on the scene with colliders to change the probability of an event occurring and have a script to start a battle if one happens. Similar techniques are used in the Pokemon style games where deep grassy areas always have a higher probability of a random battle occurring.

So to start off, we will add a couple...