Everything is working correctly, unless that i'm only able to see the canvas to each image once. Is there some way to reset this UpdateTrackedImages method when I enter the DisableMe() function? Tryed to set trackedImage to null but it didn't work... The canvas is the same to all of them, but the button will receive different information. And I should be able to come back to every one of them.
private void UpdateTrackedImages(IEnumerable<ARTrackedImage> trackedImages)
{
// If the same image (ReferenceImageName)
foreach (var trackedImage in trackedImages)
{
if (Chairs.Contains(trackedImage.referenceImage.name))
{
if (trackedImage.trackingState == TrackingState.Tracking)
{
Invoke("EnableMe", 0.5f);
}
if (trackedImage.trackingState != TrackingState.Tracking)
{
Invoke("DisableMe", 0.5f);
}
}
}
}
private void EnableMe()
{
canvas.enabled = true;
}
private void DisableMe()
{
canvas.enabled = false;
trackedImage = null;
}
I've tried to set trackedImage to null but it didn't work... The canvas is the same to all of them, but the button will receive different information. And I should be able to come back to every one of them.
It seems there is a need to reset the state of the tracked images when you enter the
DisableMe()
function, so you can see the canvas for each image again.The issue you are facing is because the
trackedImage
variable is declared inside the foreach loop and is not accessible outside of it. Therefore, when you calltrackedImage = null;
inside theDisableMe()
function, it only affects the local variable inside that function, not the ones in theforeach
loop.To resolve this, you can declare a class-level variable for trackedImage that will store the currently tracked image. Here's the modified code to achieve that:
Now, by using the currentTrackedImage variable, you should be able to enable and disable the canvas for each tracked image independently. Remember to also check if currentTrackedImage is not null before accessing it in other parts of your code.