Book Image

Unity Virtual Reality Projects

By : Jonathan Linowes
Book Image

Unity Virtual Reality Projects

By: Jonathan Linowes

Overview of this book

What is consumer “virtual reality�? Wearing a head-mounted display you view stereoscopic 3D scenes. You can look around by moving your head, and walk around using hand controls or motion sensors. You are engaged in a fully immersive experience. On the other hand, Unity is a powerful game development engine that provides a rich set of features such as visual lighting, materials, physics, audio, special effects, and animation for creating 2D and 3D games. Unity 5 has become the leading platform for building virtual reality games, applications and experiences for this new generation of consumer VR devices. Using a practical and project-based approach, this book will educate you about the specifics of virtual reality development in Unity. You will learn how to use Unity to develop VR applications which can be experienced with devices such as the Oculus Rift or Google Cardboard. We will then learn how to engage with virtual worlds from a third person and first person character point of view. Furthermore, you will explore the technical considerations especially important and possibly unique to VR. The projects in the book will demonstrate how to build a variety of VR experiences. You will be diving into the Unity 3D game engine via the interactive Unity Editor as well as C-Sharp programming. By the end of the book, you will be equipped to develop rich, interactive virtual reality experiences using Unity. So, let's get to it!
Table of Contents (18 chapters)
Unity Virtual Reality Projects
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
11
What's Next?
Index

If looks could kill


We got this far. We might as well try to kill Ethan (haha!). Here are the specifications for this new feature:

  • Looking at Ethan hits him with our line-of-sight ray gun

  • Sparks are emitted when the gun hits its target

  • After 3 seconds of being hit, Ethan is killed

  • When he's killed, Ethan explodes (we get a point) and then he respawns at a new location

The KillTarget script

This time, we'll attach the script to a new empty GameController object by performing the following steps:

  1. Create an empty game object and name it GameController.

  2. Attach a new C# script to it, using Add Component, named KillTarget.

  3. Open the script in MonoDevelop.

Here's the completed KillTarget.cs script:

using UnityEngine;
using System.Collections;

public class KillTarget : MonoBehaviour {
  public GameObject target;
  public ParticleSystem hitEffect;
  public GameObject killEffect;
  public float timeToSelect = 3.0f;
  public int score;

  private float countDown;

  void Start () {
    score = 0;
    countDown...