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();
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);
}
}
}
↧