Glusoft

Playing a video in Unity

In this tutorial you will learn playing a video in unity.

Game objet with video player

A good way to learn about this object is going to official documentation for the video player

The first thing to do is to create an empty Game object and attach a video player :


video player property - playing a video in unity

You will need multiple things, the most important one is a video, if you do not have any you can download the AMV I am using :

Homuras-Seven-Devils-AMV

After the video clip is downloaded you need to import it in Unity, by simply dragging and dropping the file into the asset folder.

You can then chose a Render mode you have a lot of choices :

list of the render mode - playing a video in unity

Camera Far Plane/Near Plane

By selecting this mode you will need to specify a Camera and the video will render in this Camera, you only have the main camera in the project so pick this one and the video will be rendered full screen.

Here is the result of using the camera mode :

result playing a video in unity

Render Texture in unity

You can chose to render the output of the video on a render texture. A render texture is a special texture that can be render in real time. You need to create one first in the assets :

creation of a render texture - playing a video in unity

After the render texture is created you will need to specify a size, the AMV I am using is in 720p that means a resolution of 1280ร—720 so I specify the sizes :

render texture size - playing a video in unity

After the texture is done we need to use it ๐Ÿ™‚

Create a 3d object: cube

In a 3d game the simplest flat object with a material is a cube, so letโ€™s create a cube to apply the render texture on it !

Yes, but what the size of the cube ? Same as before we want to have the same ratio 1280ร—720 => 12.80ร—7.20

cube size and position -playing a video in unity

Aftet the cube is created with the right size you can drag and drop the render texture on it.

Camera position and lights

When you hit play does the video is inverted ? Yes ? Try to position the camera to the opposite side, the video will look normal.
Yes it can seem weird at first but the render texture is applied on every face of the cube like any other material.

The position for my Camera is :

camera property

The orientation of the light is also important :

light property

You also need to disable the reflection of the light on the render texture, for that click on the cube inside the property of the render texture material disable :

rendering option for render texture

After all that the project should be looking good to go with a render texture ๐Ÿ™‚

Full project : playing a video in Unity

PlayingVideo