How to do it...

To implement slow motion, follow these steps:

  1. Import the BallGame package into your project and, from the Project panel, open the level named scene1_ballGame.
  2. Create a C# script class called BulletTime, and add an instance object as a component to the First Person Controller GameObject:
    using UnityEngine;     using UnityEngine.UI;     using System.Collections;      public class BulletTime : MonoBehaviour {         public float slowSpeed = 0.1f;         public float totalTime = 10f;         public float recoveryRate = 0.5f;         public Slider EnergyBar;         private float elapsed = 0f;         private bool isSlow = false;          void Update (){                     if (Input.GetButtonDown ("Fire2") && elapsed < totalTime)                 SetSpeed (slowSpeed);
             if (Input.GetButtonUp ("Fire2"))                 SetSpeed (1f);  if ...

Get Unity 2018 Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.