Unity - Videos

From NoskeWiki
Jump to: navigation, search

About

NOTE: This page is a daughter page of: Unity


Unity3D is a multi-platform 3D game engine. This page talks a little bit about how to add a video into Unity.


Playing a YouTube Video in Unity

Easiest way to add a video to Unity UI:

  • Add a "Video > Video Player" (game object to the Hierarchy).
  • Set its source URL to a to an .mp4 you uploaded to the web.
    • For YouTube: You need to generate a special (temporary) YouTube URL like: this very long URL ... I got this long URL from the $25 Unity YouTube API3 asset under "Scenes > Simple Player" when I entered the YouTube URL "https://www.youtube.com/watch?v=sL5mAbwUYpM"... it uses a fancy script to turn the YouTube URL into a place where the Video Player can actually render the video itself. Sadly it has a timestamp which so it only lasts a couple of days, so it seems worth the $25 to get Unity YouTube API3 if your heart is set on YouTube.
  • Set render mode to "Render Texture".
  • Add a "UI > Raw Image" in the location you want.
  • In the project folder then make a "Material > Render Texture" material, then drag that as the texture into the "Video Player" and "Raw Image".
    • NOTE: And/or you could attach the same texture to a 3D mesh in the scene.
  • Make sure "Video Player" has audio set to "Direct" with 1 controlled tracks.
    • Scratch that, if you want it work on Android, set it "Audio Source", then add a "Audio Source" to the same game component and drag it in as the target.

Links