Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Gamification with Unity 5.x
  • Table Of Contents Toc
  • Feedback & Rating feedback
Gamification with Unity 5.x

Gamification with Unity 5.x

By : Lauren S. Ferro
3 (2)
close
close
Gamification with Unity 5.x

Gamification with Unity 5.x

3 (2)
By: Lauren S. Ferro

Overview of this book

Are you looking at implementing gamification techniques for your business and wondering where to get a complete rundown of all the tricks and techniques? Well, you have come to the right place! This book will start right from the basics such as gameplay elements and their functionalities before gradually moving onto creating your first gamification project from scratch. You’ll be given the tools and shown how to perform various techniques for creating gamified applications in different contexts. Finally, you will implement various game elements into Unity, publish your own task management application, and get to know the best practices and approaches when designing gamified experiences.
Table of Contents (11 chapters)
close
close

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...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY