- Home /
How to make a seamless transition between movie clips?
Hello everyone. I have a few movie clips which need to be played based on user input. I have created the script but the problem is, it blinks while changing to next clip. Below are the example of my script.
c# Code
void update() { renderer.material.mainTexture = movieTexture1; movieTexture1.Play();
//movieTexture1 only play once
if(movieTexture1.isPlaying == false) { renderer.material.mainTexture = movieTexture2; movieTexture2.Play(); } }
i simply play the next clip after the current one stopped. Are there another way to do it? Thank You for your help.
Answer by Drakulo · Jan 22, 2014 at 10:05 AM
To remove the blink effect, you can use 2 different GameObjects associated with the proper movie clip as texture. Instead of changing the texture, enable or disable the GameObjects and start playing the movierespectively.
Example : GameObject A linked to movie A, GameObject B linked to movie B. Start with A enabled and B disabled. To switch from A to B, disable A, enable B and start playing the B movie texture.
thanks Drakulo. i've created the script but it still blinks. i don't think my script was correct. i've posted the script in the thread
Answer by bryanbob · Jan 23, 2014 at 03:49 AM
thank you Drakulo for the reply. Im totally new with unity scripting. to be more detail, i've created three plane objects with movieTexture. following are the script to play the clip. with this script, it blinks when playing the next clip:
using UnityEngine;
using System.Collections;
public class PlayMovieClip2 : MonoBehaviour {
public int ind= 0;
public GameObject g1;
public GameObject g2;
public GameObject g3;
// Use this for initialization
void Start () {
}
bool once = true;
// Update is called once per frame
void Update () {
if(ind==0)
{
g1.SetActive (true);
//renderer.enabled = true;
(g1.renderer.material.mainTexture as MovieTexture).Play ();
if(once)
{
StartCoroutine(PlayNext((g1.renderer.material.mainTexture as MovieTexture).duration, 1));
once = false;
}
g2.SetActive (false);
g3.SetActive (false);
}
else if(ind==1)
{
g2.SetActive (true);
//renderer.enabled = true;
(g2.renderer.material.mainTexture as MovieTexture).Play ();
if(once)
{
StartCoroutine(PlayNext((g2.renderer.material.mainTexture as MovieTexture).duration, 2));
once = false;
}
g1.SetActive (false);
g3.SetActive (false);
}
else if(ind==2)
{
g3.SetActive (true);
//renderer.enabled = true;
(g3.renderer.material.mainTexture as MovieTexture).Play ();
if(once)
{
StartCoroutine(PlayNext((g3.renderer.material.mainTexture as MovieTexture).duration, 3));
once = false;
}
g2.SetActive (false);
g1.SetActive (false);
}
else
{
g1.SetActive (false);
g2.SetActive (false);
g3.SetActive (false);
}
}
private IEnumerator PlayNext(float duration, int idx)
{
yield return new WaitForSeconds(duration);
ind = idx;
once=true;
}
}
You should not call Play more than once. This method starts playing the movie clip on your texture so calling it every frame can produce unwanted behaviours. Secondly, ins$$anonymous$$d of using a custom code to manage the video reading only once, there is a variable to manage this : $$anonymous$$ovieTexture.loop.
Cut your code in small methods, it makes it easier to understand / debug.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Video Scrubber Bar & Rewind using MovieTexture? 0 Answers
Distribute terrain in zones 3 Answers
A node in a childnode? 1 Answer