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

Acquiring a House

During this chapter, we will enable our metaverse to allow its users to settle in our world by acquiring a home. To do so, we will provide the Prefab of the houses we saw during Chapter 5, Preparing a New World for Travel, with a script that will allow a player to interact.

During this acquisition process, we will first consult the database, then, if the user has been able to obtain ownership of the building, we will update the building document in Firestore, so that it links the user’s ownership information.

In this chapter, we will cover the following topics:

  • The concept of home
  • Enabling a user to obtain a home
  • Linking a house to a player
  • Converting a house to a non-fungible token (NFT)

Technical requirements

This chapter does not require any special technical requirements, but as we will start programming scripts in C#, it would be advisable to have basic notions in this programming language. We need an internet connection to browse and download an asset from Unity Asset Store. We will continue on the project we created during Chapter 1, Getting Started with Unity and Firebase.

Remember that we have the GitHub repository (https://github.com/PacktPublishing/Build-Your-Own-Metaverse-with-Unity/tree/main/UnityProject), which will contain the complete project that we will work on here.

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/Chapter08

The concept of home

Home, abode, domicile, dwelling... we all know what the terms mean, but what about in the metaverse?

The metaverse can be a reflection of reality, where we try to emulate actions that we usually do in our lives. One of the things we can do is to get a house to make it our home. If you remember in Chapter 5, Preparing a New World for Travel, we managed to generate houses in the scene, and they had a link – a reference in Firebase Firestore. In this chapter, we will go a step further and allow our users to own those houses.

In an ideal metaverse, a user can own a house, allow friends to enter, have a party, decorate it, and meet friends to talk – sounds fun, doesn’t it? In reality, these action involves more things – for example, when a user owns a house or has permissions on other houses, we want them to be able to enter them.

The action of entering a house may sound like a very complex thing to do, but it boils down to a collision...

Enabling a user to obtain a home

The process of making a user the owner of a property is very simple, partly because we have already acquired knowledge that will provide the fundamentals to do so.

We will divide the objective into the following sections:

  • Adding a trigger to the Prefab of a house
  • Programming the script that allows us to acquire the house
  • Linking the house to a player

To start with this task, we will make modifications on the Prefabs that we have used to build the houses in the World1 scene.

Adding a trigger to the Prefab of the house

If you remember from Chapter 5, Preparing a New World for Travel, we added two Prefabs that represent houses in a scene; these Prefabs are located in the Resources folder:

  1. Go to the Assets | Resources | Prefabs | Buildings path and double-click on the Suburb House Grey Prefab to edit it.
  2. Once opened, we will create a Cube and disable the Mesh Renderer component; we will only use its Collider to...

Understanding what an NFT is

Non-Fungible Token (NFT) technology is a type of unique and indivisible digital token used to represent the ownership or authenticity of a specific digital asset. Unlike cryptocurrencies such as Bitcoin or Ethereum, which are fungible (interchangeable with each other), NFTs are unique and cannot be replaced by other tokens.

In this book, we will discuss the creation of NFTs in a didactic and testing environment, so there will be no real monetary cost.

Note: NFTs in your project

The world of NFTs is very abstract; what you want to turn into an NFT in your project depends entirely and only on the goal you want to achieve. In this book, we will deal with the creation of NFT in a didactic way, with simple examples that will lay the foundations for what you want to build in the future. There are infinite possibilities in terms of creating an NFT; you can create it from a photo, a text, a file, and so on. We will learn in the following sections how to...

Summary

Throughout this chapter, we learned how to add a collider that serves as a trigger for a user, allowing them to interact with the houses that we dynamically load into a scene. This trigger contacts the Firestore database and queries whether a building is occupied by another player or can be acquired by the current player.

We learned a new class, GUI, allowing us to display texts on screen in a very simple way, which is ideal to display messages that incite action. We programmed a script able to query and write in the database the new owner of the building. Conversely, we learned how to use the ChainSafe SDK to create NFTs from our class.

In the next chapter, we will introduce our world to the Photon SDK, an impressive framework that will turn our metaverse into a multiplayer world. With Photon, we will be able to coordinate over a network all our player’s movements; walking, jumping, turning, and running will be transmitted over the internet and accurately reproduced...

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}