Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Build Your Own Metaverse with Unity

You're reading from  Build Your Own Metaverse with Unity

Product type Book
Published in Sep 2023
Publisher Packt
ISBN-13 9781837631735
Pages 586 pages
Edition 1st Edition
Languages
Concepts
Author (1):
David Cantón Nadales David Cantón Nadales
Profile icon David Cantón Nadales

Table of Contents (20) Chapters

Preface 1. Part 1: Getting Started
2. Chapter 1: Getting Started with Unity and Firebase 3. Chapter 2: Preparing Our Player 4. Chapter 3: Preparing Our Home Sweet Home: Part 1 5. Chapter 4: Preparing Our Home Sweet Home: Part 2 6. Chapter 5: Preparing a New World for Travel 7. Part 2: And Now, Make It Metaverse!
8. Chapter 6: Adding a Registration and Login Form for Our Users 9. Chapter 7: Building an NPC That Allows Us to Travel 10. Chapter 8: Acquiring a House 11. Chapter 9: Turning Our World into a Multiplayer Room 12. Chapter 10: Adding Text and a Voice Chat to the Room 13. Part 3: Adding Fun Features Before Compiling
14. Chapter 11: Creating an NPC That Allows Us to Change Our Appearance 15. Chapter 12: Streaming Video Like a Cinema 16. Chapter 13: Adding Compatibility for the Meta Quest 2 17. Chapter 14: Distributing 18. Index 19. Other Books You May Enjoy

Streaming Video Like a Cinema

We have reached the final stretch of the book and the construction of our metaverse. It is time to fill our virtual world with fun functionalities to leave a mark on our future users. In the metaverse, you can do an infinite number of activities with your friends, such as watching a video or a film. In this chapter, we are going to discover a new Unity class, called VideoPlayer.

With VideoPlayer, we can play local videos or videos from an internet address as if they were textures, on any 3D object – fun, right? Put simply, we integrate this feature, which gives us endless new ideas. For example, you could program a cinema in which to play movies or commercials anywhere in your world. Right now, your mind probably cannot stop generating new ideas.

In this chapter, I will give you the keys to set up any future video playback system on 3D objects.

In the following screenshot, you can see the final result of the magnificent cinema screen, streaming...

Technical requirements

This chapter does not have any special technical requirements, but we will start programming scripts in C#. It would be advisable to have basic knowledge of this programming language. You’ll need an internet connection to browse and download an asset from the Unity Asset Store.

We will continue with the project we created in Chapter 1. Remember that we have the GitHub repository, https://github.com/PacktPublishing/Build-Your-Own-Metaverse-with-Unity/tree/main/UnityProject, which contains the complete project that we will work on here.

Introducing the VideoPlayer class

Unity 3D’s VideoPlayer class is a useful tool to play and control videos in real time within a game or application. This class allows you to load and play videos in different format, and offers several configuration options, such as audio track selection and image quality settings.

The VideoPlayer class can be used in a wide variety of projects, from games to educational applications, to multimedia presentations. Here are some ways in which the VideoPlayer class could help your project:

  • Integrate videos into your game: If your game needs to include videos, either to introduce the plot or to show cinematic sequences, the VideoPlayer class will allow you to play videos within the game and control their playback.
  • Multimedia presentations: If you are creating an application that includes multimedia presentations or video tutorials, the VideoPlayer class can be a useful tool to play and control the videos.
  • Educational applications...

Designing our screen

In our practical example, we will create a screen similar in shape and proportion to a cinema screen or a billboard – elongated, in full HD style. The screen that we will use to play videos is nothing more than a plane. Follow these steps:

  1. Go to our main scene, MainScene.
  2. Select the GameObject | 3D Object | Plane option from the main menu bar and rename it Screen.
  3. Use the Move, Rotate, and Scale tools to shape the plane until it looks like this:
Figure 12.2 – Adding a plane to the scene

Figure 12.2 – Adding a plane to the scene

Perfect – easy, isn’t it? You have created the sketch of the video screen. Don’t worry if, later on, when you play videos it looks distorted. We will be able to modify the proportion of the screen later on.

Now that we have the GameObject that physically represents our screen, we need to add the VideoPlayer component to give it the functionality we are looking for. To do this, simply select the...

Playing videos

Earlier, in the introduction of this chapter, we saw a spoiler of what we are going to cover in this section. We will cover both local and online video playback. For this, we will need a valid URL and a valid file, which we will look at shortly.

If you’re wondering about the video formats supported by this component, here’s a look at some of the wide variety of video formats supported:

  • MP4: This is one of the most common video formats and is widely compatible with most devices
  • WEBM: This video format is especially useful for online video streaming and is often used in web applications
  • OGV: This is an open source video format that is often used in video editing software and web browsers
  • MOV: This is a video format developed by Apple and is widely supported by Apple devices
  • AVI: This is one of the oldest video formats and is compatible with most media players
  • FLV: This is a popular video format for online video streaming and...

Summary

In this chapter, we have discovered a new Unity3D class, the VideoPlayer class, which allows us to easily play videos both online via URLs and locally via video files. We have reviewed which formats this class accepts and analyzed in detail the properties of the class.

In the next chapter, we will learn how to integrate the Oculus Quest 2 with its respective SDK into our project.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Build Your Own Metaverse with Unity
Published in: Sep 2023 Publisher: Packt ISBN-13: 9781837631735
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}