Book Image

Building an FPS Game with Unity

By : John P. Doran, jamal seaton
5 (1)
Book Image

Building an FPS Game with Unity

5 (1)
By: John P. Doran, jamal seaton

Overview of this book

Table of Contents (18 chapters)
Building an FPS Game with Unity
Credits
Foreword
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Unity, available in free and pro versions, is one of the most popular third-party game engines available. It is a cross-platform game engine, making it easy to write your game once and then port it to PCs, consoles, and even the Web, making it a great choice for both indie and AAA developers.

Building an FPS Game with Unity takes readers on an exploration of how to use Unity to create a 3D first-person shooter (FPS) title. Over the course of the book, you will learn how to work with Unity's own tools while also leveraging the powerful UFPS framework by VisionPunk and Prototype/ProBuilder 2.0 by ProCore3D. In addition, readers will learn how to create AI characters using both RAIN and Shooter AI.

After setting up the computer, you will start by learning how to create custom weapons, prototype levels, create exterior and interior environments, and breathe life into your levels. You will then polish the levels. Finally, you will create a custom GUI and menus for your title to create a complete package.

What this book covers

Chapter 1, Getting Started on an FPS, will give readers a brief overview, from a beginner's point of view, of the exciting world of Unity development for the creation of a first-person shooter (FPS) title. We will start off by creating a project and then set up our project by installing UFPS and Prototype. We'll also see how we can customize Unity's layout and organize our files effectively.

Chapter 2, Building Custom Weapons, will talk about one of the most important things in the FPS game: the weapons. In this chapter, we will create a testbed to work on and learn how to build a weapon in UFPS from a model while also learning about UFPS features such as UnitBanks and various weapon properties to give your weapons a feel "just right" for you.

Chapter 3, Prototyping Levels with Prototype, will help us take on the role of a level designer, who has been tasked to create a level prototype to prove that our gameplay is solid. We will make use of the free tool Prototype to help in this endeavor. In addition, you will also learn some beginning level designing.

Chapter 4, Creating Exterior Environments, explores the various ways to add more organic-feeling areas to your levels, making use of Unity's different terrain tools while also adding water, trees, grass, custom skyboxes, and fog to create a complete environment that can be used in your project.

Chapter 5, Building Encounters, will show how to create various types of encounters that players may experience to create effective gameplay scenarios starting with a simple turret, then creating a melee enemy using the free RAIN AI Engine as well as a ranged enemy using Shooter AI. You will then learn how to place enemies as well as spawn them into our scene. Lastly, you will learn how to place ammo and healthpacks in the level to guide players through the level.

Chapter 6, Breathing Life into Levels, will explore some of the ways we can breathe life into our levels with moving objects and more things that the player can interact with, such as exploding barrels, moving doors, and elevators.

Chapter 7, Adding Polish with ProBuilder, will take all of the pieces we created in the previous chapters and put them together to create a finished level. You will learn how to upgrade Prototype levels to using ProBuilder, gaining the ability to add materials to wall faces and create custom UVs. You will also learn how to create materials and how to mesh your levels to create a complete environment.

Chapter 8, Creating a Custom GUI, will demonstrate how to use Unity's new GUI system to create a custom GUI to replace the one given to us by UFPS to help our project stand out.

Chapter 9, Finalizing Our Project, will focus on exporting our game from Unity and then creating an Installer so that we can give it to all of our friends, family, and prospective customers.

What you need for this book

Throughout this book, we will be working within the Unity 3D game engine that you can download from http://unity3d.com/unity/download/. The projects were created using version 5.0.1, but the project should work with minimal changes.

For simplicity's sake, we will assume that you are working on a Windows-powered computer. Though Unity allows you to code in either C# or UnityScript, for this book, we will be using C#.

We will also be using assets that are available from the Asset Store in Unity, most notably UFPS which costs money ($95 normally, but it also has sales where it can be gotten for cheaper). Aside from UFPS, all of the other topics will cover how to use a free asset to accomplish things while also discussing an easier to use asset which does cost. Readers will use ProCore3D's free Prototype tool for the creation of levels while also learning how you may upgrade your project to using ProBuilder in Chapter 9, Finalizing Our Project, for advanced functionality, but it also costs money. For enemies, you will also learn how to use the free RAIN toolkit for melee enemies and how to use Shooter AI for ranged enemies, which costs money.

Who this book is for

This book is for those who want to create an FPS game in Unity and gain knowledge on how to customize it to be their very own. If you are familiar with the basics of Unity, you will have an easier time, but it should make it possible for someone with no prior experience to learn Unity at an accelerated pace.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

   void OnTriggerEnter(Collider other)
  {
    //If the player touches the trigger, and if it hasn't
           //been triggered before
    if(other.tag == "Player" && hasTriggered == false)
    {
      // Spawn a new enemy using the properties from the
      // spawnPoint object
      GameObject newEnemy = Instantiate(enemy, spawnPoint.position, spawnPoint.rotation)
                                as GameObject;
      // We only want this to happen once.
      hasTriggered = true;
    }
  }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

   void OnTriggerEnter(Collider other) 
  {
    //If the player touches the trigger, and if it hasn't
           //been triggered before
    if(other.tag == "Player" && hasTriggered == false)
    {
      // Spawn a new enemy using the properties from the
      // spawnPoint object
      GameObject newEnemy = Instantiate(enemy, spawnPoint.position, spawnPoint.rotation)
                                as GameObject;

      //Tell enemy to go to the player's position
      newEnemy.GetComponent<NavMeshAgent>().SetDestination(other.transform.position);

      // We only want this to happen once.
      hasTriggered = true;
    }
  }

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Once completed, select Create project."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/Building_FPS_Games_with_Unity.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.