- Home /
How do I Play/Pause video which is a child of vuforia image target?
I have added using UnityEngine.Video; into all of the relevant scripts: DefaultTrackableEventHandler and the myButtonActivator script (which uses raycasting in vuforia and laptop GetButtonDown(KeyCode "") to activate different on-screen buttons).
Currently, the game will compile and on keypress "A" the GameObjects become active, but I get the error that "MissingComponentException: There is no 'VideoPlayer' attached to the "MainTarget" game object, but a script is trying to access it. You probably need to add a VideoPlayer to the game object "MainTarget". Or your script needs to check if the component is attached before using it. myButtonActivator.Update () (at Assets/myButtonActivator.cs:52)" I'm guessing this means that for some reason it thinks that the image target should play a video rather than its subobjects. Can anyone please point out how to correct this?
here is the myButtonActivator script:
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video;
public class myButtonActivator: MonoBehaviour { public GameObject CarUnroll; public GameObject CompUnroll; public GameObject KitchUnroll; public GameObject OvShpUnroll; public GameObject ScrollPlane; private string btnName; public VideoPlayer CarUnr; public VideoPlayer CompUnr; public VideoPlayer KitchUnr; public VideoPlayer OvShpUnr;
void Awake()
{
CarUnr = GetComponent<VideoPlayer>();
CompUnr = GetComponent<VideoPlayer>();
OvShpUnr = GetComponent<VideoPlayer>();
KitchUnr = GetComponent<VideoPlayer>();
}
// Start is called before the first frame update
void Start()
{
CarUnroll.SetActive(false);
CompUnroll.SetActive(false);
KitchUnroll.SetActive(false);
OvShpUnroll.SetActive(false);
ScrollPlane.SetActive(false);
}
// Update is called once per frame
void Update()
{
//Laptop key control//
if (Input.GetKeyDown(KeyCode.A))
{
//turn off scroll & space
ScrollPlane.SetActive(false);
//turn on unroll
CompUnroll.SetActive(true);
CarUnroll.SetActive(true);
KitchUnroll.SetActive(true);
OvShpUnroll.SetActive(true);
}
if (Input.GetKeyDown(KeyCode.A) && CarUnr.isPlaying)
{
//Pause videoplayers
CarUnr.Pause ();
CompUnr.Pause ();
KitchUnr.Pause ();
OvShpUnr.Pause ();
}
if (Input.GetKeyDown(KeyCode.A) && CarUnr.isPaused)
{
//Play videoplayers
CarUnr.Play();
CompUnr.Play();
KitchUnr.Play();
OvShpUnr.Play();
}
if (Input.GetKeyDown(KeyCode.S))
{
//turn off unroll & space
CarUnroll.SetActive(false);
CompUnroll.SetActive(false);
KitchUnroll.SetActive(false);
OvShpUnroll.SetActive(false);
//turn on scroll layer visibility
ScrollPlane.SetActive(true);
}
if (Input.GetKeyDown(KeyCode.D))
{
//turn off unroll & scroll//
CarUnroll.SetActive(false);
CompUnroll.SetActive(false);
KitchUnroll.SetActive(false);
OvShpUnroll.SetActive(false);
ScrollPlane.SetActive(false);
//turn space layer visibility on//
//turn on space animations//
}
//Phone raycast control//
/*if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)){
btnName = hit.transform.name;
switch (btnName)
{
case "myButton1":
if (switch.btnName == myButton1);
{
}
//turn off scroll & space//
//turn on unroll layer visibility//
CompUnroll.SetActive(true);
CarUnroll.SetActive(true);
KitchUnroll.SetActive(true);
OvShpUnroll.SetActive(true);
//turn on video players//
break;
case "myButton2":
//turn off unroll & space//
CompUnroll.SetActive(false);
CarUnroll.SetActive(false);
KitchUnroll.SetActive(false);
OvShpUnroll.SetActive(false);
//turn on scroll layer visibility//
//turn on video players or animation//
break;
case "myButton3":
//turn off unroll & scroll//
CompUnroll.SetActive(false);
CarUnroll.SetActive(false);
KitchUnroll.SetActive(false);
OvShpUnroll.SetActive(false);
//turn space layer visibility on//
//turn on space animations//
break;
default:
break;
}
}
}*/
}
}
I'm pretty new to coding, so any other tips would be great! I haven't updated
Your answer
Follow this Question
Related Questions
Wheres my options for Movie textures? 0 Answers
Pause the video in unity after playing it but it will done automatically after some time of period. 0 Answers
creating play once only 1 Answer
4K video playback 2 Answers
VideoCodec module in Unity 0 Answers