Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
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
Toc

Table of Contents (20) Chapters close

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

Triggering the NPC when we are close

Do you remember a game with an NPC in which, when you approach them, the typical text Press the ‘E’ key to interact appears on the screen? That’s exactly what we’re going to program. We will create a radius of influence for the NPC; when we enter this radius, we will show the message, and if we leave, we will hide it.

The radius of influence will be a Collider. In Unity, Colliders emit a trigger when an object containing a Rigidbody component comes into contact; the same happens when the object leaves the Collider. We will use these events to create our dialog flow.

To create our area of influence, we will first add a Collider:

  1. To do this, right-click on the GameObject of our NPC called Kaya@Happy Idle and select 3D Object | Cube, then rename it Influence.
  2. Change the size of the cube to your own liking.
Figure 11.13 – Adding a cube to the scene

Figure 11.13 – Adding a cube to the scene

  1. Finally, with...
lock icon The rest of the chapter is locked
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}