Platinum trophy achievement script using playerprefs

Hello all! I have global achievements working based on number of clicks on different game objects to earn each achievement. Now I want to enable a platinum trophy that will auto-populate when the other trophies have all been earned. Any pointers on proper script to use?

Below is a sample from my existing globalachievements, but since earning is based on # of clicks on single game objects, not sure how to get the platinum trophy going since it’s not click-triggered.

public class globalachievements : MonoBehaviour
{
    //general variables
    public GameObject achNote;
    public AudioSource achSound;
    public bool achActive = false;
    public GameObject achTitle;
    public GameObject achDesc;

    //achievement 01 specific
    public GameObject ach01Image;
    public static int ach01Count;
    public int ach01Trigger = 5;
    public int ach01Code;

IEnumerator Trigger01Ach()
{
    achActive = true;
    ach01Code = 12345;
    PlayerPrefs.SetInt("Ach01", ach01Code);
    PlayerPrefs.SetInt("Ach01", 1);
    PlayerPrefs.Save();
    achSound.Play();
    ach01Image.SetActive(true);
    achTitle.GetComponent<Text>().text = "ACE ANGLER";
    achDesc.GetComponent<Text>().text = "Go Fish";
    achNote.SetActive(true);
    yield return new WaitForSeconds(7);

    //Resetting UI
    achNote.SetActive(false);
    ach01Image.SetActive(false);
    achTitle.GetComponent<Text>().text = "";
    achDesc.GetComponent<Text>().text = "";
    achActive = false;

Every time a player earns a trophy, you need to check how many trophies they have. If they have them all, then you can grant them the other plat trophy, otherwise, you just grant the one they earned and move on.

Thank you for the feedback. Below is an excerpt from my existing trophyroom script–seems that I need to set up an If statement in a new script that checks for all other trophies SetActive(true) Then award new platinum trophy.

I’m still not sure how to execute the script that would make that happen–specifically what code line would make the platinum trophy appear.

if (PlayerPrefs.GetInt("Ach01", 0) == 1)
            fishTrophy.SetActive(true);

You’re already doing it. SetActive(true). You just need a variable that tracks your platTrophy and once you are ready, turn it on. That’s it.

But yes, a collection of your trophies that you can loop through would work. Or, if you know the number of trophies you can earn, just track the number earned and compare the two.

1 Like

Thank you. I attached this script to my platTrophy2 gameobj but even when the conditions are met (verified fishtrophy & wolftrophy are active & showing in trophy room), the platTrophy2 object does not show up. any corrections on where i went wrong?

public GameObject fishTrophy;
   public GameObject wolfTrophy;
    public GameObject platTrophy2;

   void Start()
   {
       if (fishTrophy.activeInHierarchy == true &&
           wolfTrophy.activeInHierarchy == true)
       {
           platTrophy2.SetActive(true);
       }


   }

}

Well, this is in Start, so it runs once when the scene loads. If the other two trophies aren’t active by the time this Start triggers, it’s not going to turn it on. Also, if this is attached to your platTrophy2 gameobject which is off when the scene loads, Start doesn’t run on this script. Many of Unity’s magic methods require the script to be enabled and on an Active gameobject.

1 Like