0

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();
        }

    }
}
Coder
  • 499
  • 3
  • 13
  • 29
  • Use the Button component to pause and and un-pause video. Slider to rewind video. You need to register to their event. See the answer from the duplicated question. #2 for Button and 4 for Slider Component. For UI tutorial, see [here](https://unity3d.com/learn/tutorials/topics/user-interface-ui) – Programmer May 04 '17 at 00:43
  • Got it to work. Thanks for the link you have mentioned. – Coder May 04 '17 at 14:11
  • You are welcome. By the way, you shouldn't be using `MovieTexture`. See [here](http://stackoverflow.com/questions/41144054/using-new-unity-videoplayer-and-videoclip-api-to-play-video) for how to play video with new Unity's `VideoPlayer` API. – Programmer May 04 '17 at 14:15
  • Sweet! Thanks for the info. I will definitely look into. – Coder May 04 '17 at 14:39

0 Answers0