Reputation: 157
How can I have a video play in a Vuforia Image target using Unity? The Vuforia core samples seem overly complicated.
Upvotes: 0
Views: 1956
Reputation: 157
There is no need to over-complicate it. Just use a Quad, and a VideoPlayer.
The setup should look like this:
Use this script to Play and Stop the VideoPlayer. Place the script on the Image Target
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using Vuforia;
public class ImageTargetBehaviour : MonoBehaviour, ITrackableEventHandler { private TrackableBehaviour mTrackableBehaviour; public UnityEvent myStartEvent; public UnityEvent myStopEvent;
void Start()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
// When target is found
myStartEvent.Invoke();
}
else
{
// When target is lost
myStopEvent.Invoke();
}
}
}
Now make the VideoPlayer Start and Stop in the Component Inspector of this script
Upvotes: 1