I have the video play when you press the bowling ball, I can hear it playing, but I can’t see it. I’ve tried setting it to Camera near plane, far plane, render texture? But none work. The object is directly on the bowling ball. Here’s my script for reference
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class VideoPlayButton : MonoBehaviour
{
public bool isPlaying;
public GameObject movie;
public AudioSource voice;
private float movieLength, voiceLength;
private void Start()
{
voice = this.GetComponent<AudioSource>();
voiceLength = voice.clip.length;
}
public void PlayVideo()
{
movieLength = (float)movie.GetComponent<UnityEngine.Video.VideoPlayer>().length;
if(!isPlaying)StartCoroutine(StartPlaying());
}
IEnumerator StartPlaying()
{
isPlaying = true;
voice.Play();
yield return new WaitForSeconds(voiceLength + .5f);
movie.SetActive(true);
yield return new WaitForSeconds(movieLength);
movie.SetActive(false);
}
}
Thanks in advance.
Edit: Forgot to mention, the video is in .mp4 format.
Well, I can’t really start a new project lol, I already have a bit of time invested. At any rate, I got it kinda working by having it project to a render texture. But it only plays once, then reverts to being invisible again…
Well, if you, or someone else can help, this is what’s going on right now.
Ah so it is working but then the next video is supposed to play and never does? Maybe instead of coroutine try just using Update(). Maybe you can check if(currentLength >= movieLength) or store the time then do timer+=deltaTime then if(timer >= movieLength).
I don’t see why that would be the issue. I just tested it out with the same results. It plays once just fine. For some reason, the second time is either invisible, or sometimes doesn’t play at all…
Are you just trying to loop the same video? movie.GetComponent().isLooping = true?
Or if you are trying to find when the video ends I know creating a timer and manually counting will get you there.
If the videoplayer somehow just gets layered behind something after finishing a video then it is likely happening from somewhere else in your project.
I want it to start from the beginning when the video is played a second time. I just finally got it working, on near camera plane, but I can’t get it to play in the TV screen.
Here’s my current code, really not much different from before but lol
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class VideoPlayButton : MonoBehaviour
{
private float timer;
private bool isPlaying;
public string videoName;
public GameObject movie, tvScreen;
public VideoClip clip;
public AudioSource voice;
public GameObject canvas;
private float movieLength, voiceLength;
private void Awake()
{
canvas = FindObjectOfType<Canvas>().gameObject;
voice = this.GetComponent<AudioSource>();
voiceLength = voice.clip.length;
movie.GetComponent<UnityEngine.Video.VideoPlayer>().targetCamera = Camera.main;
}
public void PlayVideo()
{
movieLength = (float)movie.GetComponent<UnityEngine.Video.VideoPlayer>().length;
if(!isPlaying)StartCoroutine(StartPlaying());
}
IEnumerator StartPlaying()
{
isPlaying = true;
yield return new WaitForSeconds(.2f);
tvScreen.SetActive(true);
movie.GetComponent<VideoPlayer>().Play();
yield return new WaitForSeconds(movieLength);
tvScreen.SetActive(false);
isPlaying = false;
}
}
I really don’t understand what’s wrong, it works fine now on camera, but not on the material.