Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Gamification with Unity 5.x

You're reading from  Gamification with Unity 5.x

Product type Book
Published in Nov 2016
Publisher Packt
ISBN-13 9781786463487
Pages 328 pages
Edition 1st Edition
Languages
Concepts

Table of Contents (16) Chapters

Gamification with Unity 5.x
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. The Anatomy of Games 2. Who or What Am I? Understanding the Player 3. An Engaged Player is a Happy Player 4. Organized Chaos - Getting Ideas Out of Your Head and on to Paper 5. Sculpting the Conceptual Beast 6. Breathing Life into Your First Creation - Creating and Importing Assets for Your Application 7. Get Your Motor Running 8. Break, Destroy, and Rebuild - the Art of Playtesting and Iteration 9. Graduating Your Project to Completion 10. Being the Best That You Can Be!

Data persistence in our application


In the previous chapter, we implemented most of the logic of our application. However, every time the user closes the application, all their tasks disappear. This is because our application is not persisting data.

To make data persistent, we need in some way to store it. The first intuitive way is to store the data locally, which means saving to a file.

PlayerPrefs in Unity

Unity offers a quick and easy way to store data persistently by using PlayerPrefs, a special class where there are functions to save primitives, such as integers or strings. In the following examples, we will work with strings, but the process is the same for all the other primitives.

The Set function

It is possible to save the data by using the following line:

PlayerPrefs.SetString("Your Key", "Your Value"); 

Basically, it takes a key and a value. The key is important, because we need it when we need to get the value back, maybe in another session (the user used the application, closed...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}