Reputation: 535
I have a requirement that when a target image is found a video should be played. Now when target image is lost video should still play.
In this case I think I have to attach video to AR Camera
and when target image is found it should get activated and played. But I'm confused. What could be the best possible solution to this problem.
What I tried:
I separated those quad(Inside which I'm playing video) from Image Target and set them in front of camera(I have two image targets). Now Inside DefaultTrackableEventHandler
I added two GameObject
public GameObject Quad1;
public GameObject Quad;
Now in Start
method I'm doing this:
Quad = GameObject.Find("Quad");
Quad1 = GameObject.Find("Quad1");
Quad.SetActive(false);
Quad1.SetActive(false);
Now inside OnTrackingFound
method I have added following:
if (mTrackableBehaviour.TrackableName == "myImage1")
{
Quad.SetActive(true);
playSound("sounds/maiplayback");
}
if(mTrackableBehaviour.TrackableName == "myImage2")
{
Quad1.SetActive(true);
playSound("sounds/mainplayback2");
}
And same code in OnTrackingLost
because we have to play video even if target lost.
But when I do so, the video starts playing when the camera is on. I'm stuck. Please suggest me. Any help would be much appreciated. Thank You!
Upvotes: 1
Views: 1303
Reputation: 678
Vuforia calls Trackable Lost every time the scene loads, maybe this is the problem.
What I do to modify behaviors like this is adding an event call from DefaultTrackableBehaviour
to a function in other script.
In this case I would add on OnTrackableFound
a call to a function that makes the video object appear or start playing, that video should be attached to the ARCamera as I think you already did.
When you start playing the video have a flag activate so when the target is tracked again it doesn't misbehave with the video. And then you stop it however you like.
Something like this.
bool playing = false;
public void PlayVideo ()
{
if (!playing)
{
playing = true;
Quad1.SetActive (true);
playSound ("sounds/mainplayback2");
}
}
public void StopVideo ()
{
if (playing)
{
playing = false;
Quad1.SetActive (false);
stopSound ();
}
}
In the worst case scenario, have a second camera with the video object attached, that way there is no way Vuforia can mess with your video behaviours, you would be able to turn it on an off at will.
Upvotes: 1