Unlocking the Power of 360-Degree Video in Unity
Setting Up Your Project
Create a new Unity 3D project and name it “VR 360 Apartment.” Make sure to select the 3D template and update the project name accordingly.
Next, head over to the Unity Asset Store and download the Apartment Kit asset. This asset is perfect for demonstrating the power of 360-degree video in Unity.
Recording a 360-Degree Video
To record a 360-degree video, we’ll use Unity’s Recorder package.
- Go to Window > Package Manager and switch to the Unity Registry.
- Install the Recorder package by Unity Technologies.
- Go to Window > General > Recorder > Recorder Window.
- Add a new recorder by selecting “Movie” from the drop-down menu.
- Configure the movie settings as follows:
- Source: 360 View
- Camera: MainCamera
- Output Dimensions: 4096 x 2048
- Cube Map Size: 2048
- Deselect Record In Stereo
- Include or exclude audio (optional)
- Set the output file path and name
- Click the play button in the Unity Editor to start recording.
- While in Play Mode, click Start Recording in the Recorder Panel.
- After 30 seconds (or longer, depending on your needs), stop recording.
Adding 360-Degree Capability to Your Video
The recorded video will appear distorted because it lacks metadata about its 360-degree capabilities. To fix this, we’ll use Google’s Spatial Media Metadata Injector tool.
- Download the Spatial Media Metadata Injector tool from the official repository.
- Extract the zipped folder and run the Spatial Media Metadata Injector.exe file.
- Open the recorded video file and click Open.
- Click Inject Metadata to add the necessary metadata to the video.
Uploading Your 360-Degree Video
Once you’ve added the metadata, your video is ready to be uploaded to YouTube or played in a compatible video player. You can pan around the 360-degree video by holding the left mouse button and moving around.
// Example code for playing 360-degree video in Unity
using UnityEngine;
public class Play360Video : MonoBehaviour
{
public VideoPlayer videoPlayer;
void Start()
{
videoPlayer.Play();
}
}