How can I make the application remember what tracker was last tracked?
I need this for a kind of history menu where you should be able to get information about the last object.
What I'v tried so far is puting this code in ImageTargetBehaviour.cs:
public void update() { if (this.mStatus == Status.TRACKED) { if (gameObject.tag == "Object1") { PlayerPrefs.SetInt("LatestSeen", 1); } else if (gameObject.tag == "Object2") { PlayerPrefs.SetInt("LatestSeen", 2); } else if (gameObject.tag == "Object3") { PlayerPrefs.SetInt("LatestSeen", 3); } else if (gameObject.tag == "Object4") { PlayerPrefs.SetInt("LatestSeen", 4); } else if (gameObject.tag == "Object5") { PlayerPrefs.SetInt("LatestSeen", 5); } else if (gameObject.tag == "Object6") { PlayerPrefs.SetInt("LatestSeen", 6); } else if (gameObject.tag == "Object7") { PlayerPrefs.SetInt("LatestSeen", 7); } else if (gameObject.tag == "Object8") { PlayerPrefs.SetInt("LatestSeen", 8); } } }
And then I try to grab these variables from my menu with this code in another c# script:
activeARObject = PlayerPrefs.GetInt("LatestSeen"); if(activeARObject == 1){ showHistory1 = true; }else if(activeARObject == 2){ showHistory2 = true; }else if(activeARObject == 3){ showHistory3 = true; }else if(activeARObject == 4){ showHistory4 = true; }else if(activeARObject == 5){ showHistory5 = true; }else if(activeARObject == 6){ showHistory6 = true; }else if(activeARObject == 7){ showHistory7 = true; }else if(activeARObject == 8){ showHistory8 = true; }
What is wrong with this code? :P
First off you probably want to use this method signature (capitalization matters):
Second, you might be interested in the object's name, rather than its tag:
Finally, you may need to add a check for the DETECTED state as well, if you are tracking frame markers:
- Kim