Search Unity

Question Playing video clips OnMouseDown

Discussion in 'Audio & Video' started by Gimbals, Dec 5, 2020.

  1. Gimbals

    Gimbals

    Joined:
    Dec 5, 2020
    Posts:
    1
    Hello, could somebody please help my with this script, I'm bashing my head on the wall trying to figure it out, thanks!

    So I have 2 video clips in an array. I want video clip [0] to loop on awake, and OnMouseDown have video clip [1] play. But at the end of video clip [1] go back to video clip [0] and continue looping. The code I have so far works, but I can't make it go back to clip [0] after OnMouseDown. Can anyone help? Thanks.

    using UnityEngine;
    using UnityEngine.Video;

    public class Mushroom : MonoBehaviour
    {
    public VideoClip[] videoClips;
    private VideoPlayer videoPlayer;
    private int videoClipIndex;

    private void Awake()
    {
    videoPlayer = GetComponent<VideoPlayer>();

    }

    // Start is called before the first frame update
    void Start()
    {
    videoPlayer.clip = videoClips[0];
    videoPlayer.isLooping = true;


    }

    // Update is called once per frame
    void Update()
    {

    }


    void OnMouseDown()
    {

    videoPlayer.clip = videoClips[1];
    videoPlayer.Play();

    Debug.Log("Collider was touched");
    }




    }