Search Unity

Creating an Achievement System

Discussion in 'Community Learning & Teaching' started by cgcookie, Dec 16, 2011.

  1. cgcookie

    cgcookie

    Joined:
    Dec 1, 2011
    Posts:
    37

    Attached Files:

    tigerleapgorge likes this.
  2. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
    Very nice, thanks for sharing!
     
  3. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    Very good tutorial for achievement system;) Now need how to save and load from an menu the pre required trophies from in-game ,and see the unlocks on the unlocks menu for example.
     
  4. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    this is the AchievemnentManagerScript:
    Code (csharp):
    1. //trophies Textures to unlock.
    2. var firstStepTex : Texture;
    3. var masterTexture : Texture;
    4. //trophy booleans, unlocked.
    5. private var FirstStepTake : boolean;
    6. private var secondStepTake : boolean;
    7. var edgeMargin;
    8. ////trophy sound.
    9. var TrophySound : AudioClip;
    10. function Start()
    11. {
    12.  edgeMargin = Screen.width * .05;
    13. }
    14. //this is the first trophy.
    15. function MasterMind()
    16. {
    17.  if(!secondStepTake)
    18.  {
    19.   unlockAchievement(masterTexture);
    20.   secondStepTake = true;  
    21.   audio.PlayOneShot(TrophySound);  
    22.  }  
    23. }
    24. //this is the second trophy.
    25. function playerMove()
    26. {
    27.  if(!FirstStepTake)
    28.  {
    29.   unlockAchievement(firstStepTex);
    30.   FirstStepTake = true;
    31.   //Debug.Log("Trophy UP;)");
    32.   audio.PlayOneShot(TrophySound);  
    33.  }
    34. }  
    35. function unlockAchievement(achievementText : Texture)
    36. {
    37.  var go : GameObject = new GameObject("Achievement Object");
    38.  go.transform.position = Vector3(0,0,Time.time);
    39.  go.transform.localScale = Vector3(0,0,0);
    40.  var guitext : GUITexture = go.AddComponent(GUITexture);
    41.  guitext.texture = achievementText;
    42.  guitext.pixelInset.width = achievementText.width;
    43.  guitext.pixelInset.height = achievementText.height;
    44.  guitext.pixelInset.x = Screen.width * 1.1; //Screen.width - achievementText.width - edgeMargin;
    45.  guitext.pixelInset.y = Screen.height -  achievementText.height - edgeMargin;
    46.  
    47.  var achievementScript : AchievementScript = go.AddComponent(AchievementScript);
    48.  achievementScript.edgeMargin = edgeMargin;
    49. }

    this is the unlocks example:

    Code (csharp):
    1. var trophySystemScript : TrophyManager;
    2. function OnTriggerEnter(other : Collider)
    3. {
    4.  if(other.gameObject.tag == "Trophy")
    5.  {
    6.   AchievementManagerScript.playerMove();
    7.  
    8.  }
    9.  if(other.gameObject.tag == "Finish")
    10.  {
    11.   AchievementManagerScript.MasterMind();
    12.  
    13.  }
    14. }
    15.  
    Happy trophies:)
     
    tigerleapgorge likes this.
  5. robounited

    robounited

    Joined:
    Oct 15, 2012
    Posts:
    2
    the notification tutorial is great, but how do you do an achievement scene that shows locked/unlocked achievements when the notification shows in game.

    p.s. when i go back to the main menu everything resets including achievement notifications, how do you change this.