O'Reilly logo

Unity Game Development Scripting by Kyle D'Aoust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Let's check the achievements

Next, we will add the functions that will actually check for achievements. These are the functions we will call when we want to check whether the player's stats have unlocked any achievements.

Checking a specific achievement

The CheckAchievement function will allow us to check for a single achievement. It takes a string, which is the achievement to check for. From here, it runs a switch statement to decide which achievement to modify. Add this function to your script. This function can be used when loading a menu, which shows the player's achievements and can be used to prevent unlocking the same achievement more than once:

void CheckAchievement(string Achievement) { switch(Achievement) { case "Kills": Kills(PlayerPrefs.GetInt("PlayerKills")); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required