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 :
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 :
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 :
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 :
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 :
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 :
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
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 :
The orientation of the light is also important :
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 :
After all that the project should be looking good to go with a render texture 🙂
Full project : playing a video in Unity