ACTIVATING CUTSCENES WITH TRIGGERS
This Unity 3D tutorial will show you how to add triggers that activate videos acting as cutscenes.
Note: This tutorial is for projects that already have an environment and a moving character. If you want to test out the triggers without an environment and player, you can create a cube with a Rigidbody component in open space, acting as our player, and then when we get to adding the trigger, you can add it in just below the cube, so on play, it will fall and hit the trigger.
First off, we have to add a trigger. To do this, we add a 3D cube to the scene and place it where the player will move to. Make sure there is no way to pass through the area without touching it. We can now rename the cube to 'cutscene1' and modify it in the inspector. First, uncheck the box next to the MeshRenderer. This makes it so it's invisible. Next, in the Box Collider component, check the box that says 'Trigger'. Now, we can go into our Player GameObject and click on add new component, and then add a new script, and we can name this Cutscenes. Once it has loaded in, we can double click on it to open it up in our script editor. For the next part, which is writing the code, you can either copy and paste it from the PDF below, type it out by hand, or watch my video tutorial, which is at the top of this page.
Also, on line 19, you can change the '10f' to the length of your video clip in seconds, but with an 'f' added to the end of it.
Now that you have the script, we can go back into Unity and add everything else. First, we can create a new camera GameObject and name it 'cutscene1Cam'. After that, we can uncheck the box next to the name of it, so that it won't be on at first when we play it. Next, we can click Add Component and add a Video Player. We can then right-click on the Assets folder in the Project Window, and click import new asset. Here you can import your video clip. In the Video Player, drag in the camera component and your video clip. Switch the Render Mode from 'Camera Far Plane' to 'Camera Near Plane'. Now, go into your Player. Here you can drag the cutscene1Cam and your own camera showing the player into the labeled spaces. Now you can press play to test everything out. When you move your player through the area where the trigger is, the video should play. After it plays, you can continue to move your character, but you cannot play the video again.