How can I have a video play in a Vuforia Image target using Unity? The Vuforia core samples seem overly complicated.
1 Answers
1
votes
There is no need to over-complicate it. Just use a Quad, and a VideoPlayer.
- Create a Quad as a child of the Image target
- Create a VideoPlayer as child of the Quad. Be sure to set the Video Clip property to the video you want to play
The setup should look like this:
- Set the Renderer property of the VideoPlayer to the previously created Quad
- Uncheck the Play on Wake property on the VideoPlayer
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