Currently, I can get my movie player to pause and rewind if I press P and the spacebar, but how can I apply it to a Unity GUI button instead of pressing P and the spacebar? I'm trying to recreate a touchscreen using Unity 5.2, so no keyboard will be require.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
[RequireComponent (typeof(AudioSource))]
public class MoviePlayer : MonoBehaviour {
public MovieTexture movie;
private AudioSource audio;
void Start ()
{
GetComponent<RawImage>().texture = movie as MovieTexture;
audio = GetComponent<AudioSource>();
audio.clip = movie.audioClip;
movie.Play();
audio.Play();
}
void Update ()
{
if (Input.GetKeyDown(KeyCode.P) && movie.isPlaying)
{
movie.Pause();
}
else if (Input.GetKeyDown(KeyCode.P) && !movie.isPlaying)
{
movie.Play();
}
else if (Input.GetKeyDown(KeyCode.Space))
{
movie.Stop();
movie.Play();
}
}
}