- Home /
How to show a GameObject on screen only when the image tracker tracks the target image?
When I track the target image a sprite prefab appears over it. I also want to have a GameObject containing an image and a button to appear at the bottom of the screen when the image is tracked and hide when it is not.
As I understand I need to write a script with obj.SetActive function, but I do not know how to trigger that function only when image tracking is happening.
when the image tracking starts call obj.SetActive(true);
when the image tracking stops call obj.SetActive(false);
You could try something like this:
if (obj.activeSelf)
{
if (ARSession.state != ARSessionState.SessionTracking) //not certain this will happen if the image is no longer tracked
{
obj.SetActive(false);
}
}
else
{
if (ARSession.state == ARSessionState.SessionTracking)
{
obj.SetActive(true);
}
}
inside of an Update()
. obj
being the object you would like to activate/deactivate obviously. I wish I could test it for you but no matter what I do all I ever get when using AR is a black screen and have since given up trying to use it.
Your answer
Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Game optimization using .SetActive() slowing down game. 0 Answers
GameObject SetActive not working 1 Answer
SetActive(true) not working 4 Answers
set active and performance unity 0 Answers