Vuforia saving items on image recognition

I have a scavenger hunt going where you find 9 different elements. Only 4 have the special ‘token’. When you view the specific elements there is a token on the bottom of the screen that shows up as collected. Problem is, I can’t figure out how to save this using playerprefs so that you can collect all 4 tokens, even if you close out of the game. Here is the token script

using UnityEngine;
using Vuforia; using System.Collections;

public class token_icon : MonoBehaviour, ITrackableEventHandler {

private TrackableBehaviour mTrackableBehaviour;

public GameObject token;
public GameObject lime_token;
public GameObject loconut_token;
public GameObject crown_token;
public GameObject gin_token;

void Start()
{
   mTrackableBehaviour = GetComponent<TrackableBehaviour>();
   if (mTrackableBehaviour)
   {
       mTrackableBehaviour.RegisterTrackableEventHandler(this);
   }
}

public void OnTrackableStateChanged(
                               TrackableBehaviour.Status previousStatus,
                               TrackableBehaviour.Status newStatus)
{
   if (newStatus == TrackableBehaviour.Status.DETECTED ||
       newStatus == TrackableBehaviour.Status.TRACKED)
   {
       token.SetActive(true);
   }
   else
   {
       token.SetActive(false);
   }
}
}

Using code tags properly

1 Like

As for your issue, you can simply save a 1 into the desired PlayerPrefs key representing that the object has been found.

bool foundThisThing = false;
string myThingName = "Thing";

void Start() {
foundThisThing = PlayerPrefs.GetInt(myThingName, 0) == 1;
}

//when you see the thing
foundThisThing = true;
PlayerPrefs.SetInt(myThingName, 1);