Building an RPG with Unity 2018
eBook - ePub

Building an RPG with Unity 2018

Leverage the power of Unity 2018 to build elements of an RPG., 2nd Edition

  1. 366 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Building an RPG with Unity 2018

Leverage the power of Unity 2018 to build elements of an RPG., 2nd Edition

About this book

Build a high-end, multiplayer role-playing game (RPG) from scratch with C# and Unity 2018

Key Features

  • Get insights into Unity's user interface (UI) system and and build UIs for your RPG
  • Implement artificial intelligence (AI) to build intelligent entities that take your game to the next level
  • Develop multiplayer features for an RPG using Unity 2018

Book Description

In a role-playing game (RPG), users control a character, usually in the game's imaginary universe. Unity has become a top choice for developers looking to create these kinds of immersive RPGs.

Building an RPG with Unity 2018, based on building some of the most common RPG features, teaches you tips, tricks, and techniques that can be applied to your own game.

To start with, the book guides you through the fundamentals of role-playing games. You will learn the necessary aspects of building an RPG, such as structuring the game environment, customizing characters, controlling the camera, and designing other attributes such as inventory and weapons. You will also explore designing game levels by adding more features. Once you have understood the bigger picture, you will understand how to tackle the obstacles of networking in Unity and implement multiplayer mode for your RPG games.

By the end of the book, you will be able to build upon the core RPG framework elements to create your own immersive games.

What you will learn

  • Construct a framework for inventory, equipment, characters, enemies, quests, and game events
  • Understand how to load and unload scenes and assets
  • Create multiplayer game settings for your RPG
  • Design a UI for user input and feedback
  • Implement AI for non-character players
  • Customize your character at runtime

Who this book is for

Building an RPG with Unity 2018 is for you if you are a programmer interested in developing and further enhancing your skills when developing RPGs in Unity 2018. This book does not cover the basics of Unity, and so is for intermediate or more advanced users.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Building an RPG with Unity 2018 by Vahé Karamian in PDF and/or ePUB format, as well as other popular books in Computer Science & Desktop Applications. We have over one million books available in our catalogue for you to explore.

Information

Inventory System

The inventory system is one of the most critical components of an RPG. It will be used to store all important game elements that the player will need in your game environment. This chapter will guide you on how to create a simple generic inventory system that can be utilized and extended as you see fit.
Here is a breakdown of the chapter:
  • Designing an inventory system
    • Weighted inventory
    • Determining item types
  • Creating an inventory item
    • Creating the prefab
    • Adding an inventory item agent
    • Inventory items defined as prefabs
  • Designing an inventory interface
    • Creating the inventory UI framework
    • Designing a dynamic item viewer
      • Adding a scroll view
      • Adding elements to PanelItem and Scroll View
      • Adding txtItemElement dynamically
    • Building the final inventory item UI
  • Integrating the UI with the actual inventory system
    • Hooking the category buttons and displaying the data
    • Testing the inventory system
  • Inventory items and the player character
    • Applying inventory items
    • How it looks
There is a lot of work ahead of us in this chapter. Let's get started!

Designing an inventory system

As with everything else we have discussed thus far, designing your inventory system will also be heavily dependent on your game. There are many different types of inventory system mechanics that you can study and choose based on its relevance to your game.

Weighted inventory

I will be leaning towards implementing what is called the weighted inventory. In this type of inventory system, each item or piece of equipment is assigned a numerical value that represents the weight of the item. This, in return, is used to determine how much inventory the player can carry at any given time during game play. This makes sense for our RPG, if you think about it.
Consider the following as an example: assume you are a hiker who wants to climb Mount Ararat. The climb itself will take a certain amount of time. During the climb, you will need to carry with you the necessary equipment to complete the journey or climb. Realistically, there are several crucial items that you, as the hiker, will need to carry with you, such as those shown in the following list:
  • Clothing
  • Tents
  • Sleeping bags
  • Boots
  • Ice breakers
  • Food
  • Light source
  • Personal items
Each one of the categories listed above has a specific weight associated to it in real life. Therefore, when you are planning your hike, you will need to plan ahead and see how you can meet your climbing needs, while in the meantime also reducing the amount of items and the total weight of the items you will need to carry on your back during the journey. The actual logistics are a little more involved, but you get the picture.
It is no different in our RPG. The player character can only carry a certain number of items and/or equipment with them for their journey. For instance, the player character cannot carry twenty different types of weapon at any given time! It would be just impossible, realistically speaking. So it would be a nice touch to put some realism into the game play.
Also, just like in real life, the heavier the equipment one has to carry, the more energy it will take. So, we can also incorporate such a system for our game. For instance, carrying too many weapons will have a major effect on the player character over a long period of time. First of all, it will reduce its speed and movement drastically; secondly, it can have a major impact on the health of the player. This is where your creativity and design skills will come into play. You are the master of the game, and you determine how you want to implement it!
I am going to keep it simple for the sake of demonstration!

Determining item types

For starters, we will concentrate on some of the basic item types that we would like to define in our game, such as weapons, armor, and clothing. On top of this, we can also add health packets, potions, and collectibles.
We will create three new scripts named BaseItem.cs, InventoryItem.c, and InventorySystem.cs. The BaseItem class will hold the generic properties for all items, just like the BaseCharacter class we defined previously. The InventoryItem class will inherit the BaseItem class and define the item type.
A listing of BaseItem.cs is as follows:
using System;
using UnityEngine;
namespace com.noorcon.rpg2e
{
[Serializable]
public class BaseItem
{
public enum ItemCatrgory
{
Weapon = 0,
Armour = 1,
Clothing = 2,
Health = 3,
Potion = 4
}
[SerializeField]
private string name;
[SerializeField]
private string description;
public string Name
{
get { return name; }
set { name = value; }
}
public string Description
{
get { return description; }
set { description = value; }
}
}
}
The main idea in the preceding code is ItemCateogry. At the moment, I have kept it to only five different types of category that the inventory would keep track of.
A category could have multiple item types. For instance, there are different types of weapons and so on.
A listing of InventoryItem.cs is as follows:
using System;
using UnityEngine;
namespace com.noorcon.rpg2e
{
[Serializable]
public class InventoryItem : BaseItem
{
[SerializeField]
private ItemCatrgory category;
[SerializeField]
private float strength;
[SerializeField]
private float weight;
public ItemCatrgory Category
{
get { return category; }
set { category = value; }
}
public float Strength
{
get { return strength; }
set { strength = value; }
}
pu...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Dedication
  4. Packt Upsell
  5. Contributors
  6. Preface
  7. What is an RPG?
  8. Planning the Game
  9. RPG Character Design
  10. The Game Mechanics
  11. GameMaster and Game Mechanics
  12. Inventory System
  13. User Interface and System Feedback
  14. Multiplayer Setup
  15. Other Books You May Enjoy