Question by
german2209 · Apr 17, 2016 at 12:14 PM ·
videoplaymouseclickmovietexture
Play only selected video
I have 5 cubes in a scene, and 1 different video attached to each one. I want to play only video 1 on cube 1 when cube 1 is clicked, video 2 on cube 2 when cube 2 is clicked and so on.
I have tryed the folowing code, but when I click on any place inside my scene all the videos start to play at the same time, how can I tell to play only the video attached to the clicked cube?
Thanks in advance for any help!
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class PlaySelected : MonoBehaviour
{
public MovieTexture movie;
// Use this for initialization
void Update()
{
if (Input.GetMouseButtonDown(0))
{
GetComponent<Renderer>().material.mainTexture = movie;
if (movie.isPlaying)
{
movie.Stop();
}
else
{
movie.Play();
}
}
}
}
Comment