I want my UI rawimage to do something when the movie texture has finished
Ok so i have a rawImage and this script is within it
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class PlayVideo : MonoBehaviour {
public MovieTexture movie;
RawImage rawImageComp;
AudioSource audioS;
// Use this for initialization
void Start()
{
rawImageComp = GetComponent<RawImage>();
audioS = GetComponent<AudioSource>();
PlayClip();
}
void PlayClip()
{
audioS.clip = movie.audioClip;
audioS.Play();
rawImageComp.texture = movie;
movie.Play();
}
}
I don't know how to do a wait until the movie ends and move to the next scene, if you know how, please be sure to re-write how to do this, i am a visual learner.
Answer by ScaniX · Jan 16, 2017 at 01:29 PM
Add a check if it is still playing in the Update() function:
public MovieTexture movie;
RawImage rawImageComp;
AudioSource audioS;
private bool movieStarted;
// Use this for initialization
void Start()
{
rawImageComp = GetComponent<RawImage>();
audioS = GetComponent<AudioSource>();
PlayClip();
}
void PlayClip() {
audioS.clip = movie.audioClip;
audioS.Play();
rawImageComp.texture = movie;
movie.Play();
movieStarted = true; // paranoia, only necessary if Update() is called before this one
}
void Update() {
if (movieStarted && !movie.isPlaying) {
movieStarted = false; // avoid getting here after the scene change was triggered, because it might be done asynchronously
// Do something great here, probably this:
SceneManager.LoadScene("TheSceneAfterTheMovie");
}
}
You are so amazing! it is working perfectly but the Scene$$anonymous$$anager.LoadScene didn't work so i changed it with Application.LoadLevel("$$anonymous$$yLevel"); and it worked! <3 i rewarded you
Your answer
Follow this Question
Related Questions
How to show and remove text before player has started the game? 1 Answer
Revers Object Transfrom using an array problem in UI !! 0 Answers
Temple Run and Subway Surfers Game Over Implementation? 0 Answers
GameObject.Find always returns null even when the object exists 1 Answer
Move gameObject on UI Button Press 2 Answers