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

Turning Our World into a Multiplayer Room

Metaverse and multiplayer are definitions that often go hand in hand; it is hard to imagine a single-player metaverse. One of the most fun features a virtual world can have is for it to interact with other players in real time, and for those users to interact with friends and other users in different scenarios and activities.

In this chapter, we will focus on adding this feature to our project. We will achieve this with Photon SDK, a powerful framework that offers easy integration for our Unity3D projects. We will learn how to send the movements and animations through the network so that all the users of our metaverse are synchronized in real time.

Photon offers an SDK for integrating text chat and voice chat into our project, with all the services being under the same provider. This is one of the reasons why I chose Photon for this book. We will see this in Chapter 10, Adding Text and a Voice Chat to the Room.

We will cover the following...

Technical requirements

This chapter does not require any special technical requirements, but we will start programming scripts in C#. Therefore, it’s advised that you have basic notions of this programming language.

We need an internet connection to browse and download an asset from the Unity Asset Store. We will continue using the project we created during Chapter 1, Getting Started with Unity and Firebase. Remember that we have this book’s GitHub repository, which contains the complete project that we will work on here: https://github.com/PacktPublishing/Build-Your-Own-Metaverse-with-Unity/tree/main/UnityProject.

You can also find the complete code for this chapter on GitHub at: https://github.com/PacktPublishing/Build-Your-Own-Metaverse-with-Unity/tree/main/Chapter09

Getting started with Photon SDK

Photon SDK is a set of tools and services for developing networked games in Unity3D. Photon SDK allows you to create real-time multiplayer games, including online, cooperative and competitive games.

Photon SDK offers a scalable and reliable networking solution that allows you to create multiplayer online games with low latencies and a large number of concurrent players. Some of the features and benefits of Photon SDK include the following:

  • Real-time connection: Photon SDK enables the creation of real-time, online games, which means players can interact in real time without any lag.
  • Ease of use: Photon SDK provides an easy-to-use interface that simplifies the creation of multiplayer games. It also provides detailed documentation and technical support to help you integrate Photon SDK into your Unity project.
  • Scalability: Photon SDK is capable of handling a large number of simultaneous players, making it ideal for massively multiplayer...

Synchronizing movements and animations in the network

After downloading and configuring Photon SDK, we will move on to the more technical part of this chapter. Throughout the following pages, we will learn how to connect the tools offered by this SDK to provide multiplayer technology to our project. You will be surprised how easy Photon makes this.

Photon offers a series of ready-made scripts that we only have to attach to the Prefab that represents the player. That is to say, all the ugly parts of programming such as synchronizing movements and animations are done for us, so we only have to know how to integrate them. That’s what we will deal with in this chapter.

Preparing the player Prefab

Before we start, we must consider the details. Photon SDK will now be in charge of the scene changes and instantiating the player in the scene. So, for it to be able to perform these actions, the Prefabs that are going to be instantiated in the scene must be in a path under the...

Testing synchronization with another user

Testing a local multiplayer game is a tedious and complicated task. We need to replicate a local development environment that allows at least two players to connect so that they can test our code.

One of the options that comes to mind is to create a build of our project and run it on other computers, or even launch it on our computer and then launch the project in the Unity editor to test two players.

But this would be terrible – we would have to compile for every test we do and, if our code fails, we would have to create a new build for each fix. Fortunately, a team of developers have developed a tool that will change our lives called ParrelSync.

Introducing ParrelSync

ParrelSync is an extension for the Unity editor that allows users to test a multiplayer game without building the project by having another Unity editor window open and reflecting the changes of the original project.

In short, ParrelSync will create a copy...

Summary

Throughout this chapter, we learned all about Photon and we created a new project in the Dashboard area. We also learned how to convert our single-player metaverse into a spectacular multiplayer metaverse. With Photon SDK, we managed to easily add new scripts that can synchronize all the players, along with their animations and movements, on the network.

We also learned how to change scenes and have them transmitted to the network to see how users appear and disappear from our scene when we change rooms in Photon.

In the next chapter, we will learn how to integrate two new services offered by Photon – Photon Chat and Photon Voice. With these services, we will add voice chat and text chat features to our metaverse.

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}