Log in or register to post comments

Remembering what was last tracked

October 21, 2011 - 8:42am #1

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

Re: Remembering what was last tracked

October 23, 2011 - 8:09pm #2

First off you probably want to use this method signature (capitalization matters):

public void Update()
{

}

Second, you might be interested in the object's name, rather than its tag:

if (gameObject.name == "Object1")
{

}

Finally, you may need to add a check for the DETECTED state as well, if you are tracking frame markers:

if (this.mStatus == Status.DETECTED || this.mStatus == Status.TRACKED)
{

}

- Kim

Log in or register to post comments