The most concise implementation of video playback in the new version of Unity

There are two main ways to play video in Unity before. The first is to play in the game object, the principle is that the camera illuminates the plane, and the second is UI playback, similar to textures (don't forget that MovieTexture is a subclass of texture).
Now the new version of Unity has added a new way to play video, which is to create a new VideoPlayer that comes with .6 directly in the project interface.
There are three steps to putting elephants in the refrigerator, and the same is true for making videos.
1. Make a video, drag the desired video into Unity. Select the VideoClip format, apply
2. Create a new VideoPlayer in the Project interface , and a new VideoPlayer will be added. The first item selects the VideoClip format and drags your video into the second input box. The following are the settings for one: 1 Play On Awake: Autoplay when script loads. 2.Wait For First Frame: Determines whether to play after the first frame is loaded, which is valid only when Play On Awake is checked. This prevents the first few frames of the video from being skipped. (It is found that the video cannot be played automatically after checking it during use, and the reason is unknown) 3.Loop: Loop. 4.Playback Speed: Playback speed. 5. Video Player also provides a variety of video rendering methods, including Camera Far Plane, Camera Near Plane, Render Texture, Material Override, Api Only. 3. How to add sound? This is the easiest! Just create a new AudioSource on the VideoPlayer object. This way, your unity video is ready to play! If you don't believe me, try adding the code! (Note: I am using the VRTK input, if there is a difference, you can change it yourself)






using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
using UnityEngine.Video;

public class MoviePlayer : VRTK_InteractableObject
{
    public VideoPlayer videoPlayer;
    bool isPlay;
        void Start () {
        isPlay = false;
    }

    public override void StartUsing(VRTK_InteractUse currentUsingObject = null)
    {
        VideoPlayer videoplayer = videoPlayer.GetComponent<VideoPlayer>();
        if (!isPlay)
        {
            videoplayer.Play();
            isPlay = true;
        }
        else {
            videoplayer.Pause();
            isPlay = false;
        }
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324408986&siteId=291194637