PacktLib: Unity 4.x Cookbook

Unity 4.x Cookbook

Credits

About the Authors

About the Reviewers

www.PacktPub.com

Preface

Getting Started with Unity 4.x

Introduction

Installing Unity 4.x

Setting your preferences

Understanding and optimizing the User Interface

Saving assets created in Unity as Prefabs

Discovering Unity's content

Importing your own content

Importing Unity packages into your project

Importing custom packages into your project

Exporting custom packages from your project

Adding custom packages to Unity's quick list

Using the Project browser

Using Cameras

Introduction

Creating a picture-in-picture effect

Switching between multiple cameras

Customizing the lens flare effect

Making textures from screen content

Zooming a telescopic camera

Making an inspect camera

Creating particle effects using Shuriken

Displaying a mini-map

Creating Maps and Materials

Introduction

Creating a reflective material

Creating a self-illuminated material

Creating specular texture maps

Creating transparency texture maps

Using cookie textures to simulate a cloudy outdoor

Creating a color selection dialog

Combining textures in real time through the GUI

Highlighting materials at mouse over

Animating textures by looping through array of materials (for example, simulated video)

Disabling culling for a material

Creating GUIs

Introduction

Displaying a digital clock

Displaying an analogue clock

Displaying a compass to show player direction

Displaying a radar to indicate relative locations of objects

Displaying images for corresponding integers

Displaying images for corresponding floats and ranges

Displaying a digital countdown timer

Displaying a countdown timer graphically (5, 4, 3, 2, 1 – blast off)

Displaying a countdown timer graphically as a pie-chart style clock

Creating a message that fades away

Displaying inventory texts for single object pickups

Displaying inventory icons for single object pickups

Managing inventories with a general purpose PickUp class

Controlling the scrollbar with the mouse wheel

Implementing custom mouse cursor icons

Controlling Animations

Introduction

Configuring a character's Avatar and Idle animation

Moving your character with Root Motion and Blend Trees

Mixing animations with Layers and Masks

Overriding Root Motion via script

Adding rigid props to animated characters

Making an animated character throw an object

Applying ragdoll physics to a character

Rotating the character's torso to aim

Playing and Manipulating Sounds

Introduction

Matching audio pitch to animation speed

Adding customizable volume controls

Simulating a tunnel environment with Reverb Zones

Preventing the AudioClip from restarting if already playing

Waiting for audio to finish before auto-destructing an object

Making a dynamic soundtrack

Working with External Resource Files and Devices

Introduction

Loading external resource files – by Unity Default Resources

Loading external resource files – by manually storing files in Unity's Resources folder

Loading external resource files – by downloading files from the Internet

Saving and loading player data – using static properties

Saving and loading player data – using PlayerPrefs

Saving screenshots from the game

Control characters in Unity with the Microsoft Kinect using the Zigfu samples

Animating your own characters with the Microsoft Kinect controller

Homemade mocap by storing movements from the Microsoft Kinect controller

Setting up a leaderboard using PHP/MySQL

Working with External Text Files and XML Data

Introduction

Loading external text files using the TextAsset public variable

Loading external text files using C# file streams

Saving external text files with C# file streams

Loading and parsing external XML files

Creating XML text data manually using XMLWriter

Creating XML text data automatically through serialization

Creating XML text files – saving XML directly to text files with XMLDocument.Save()

Managing Object States and Controlling Their Movements

Introduction

Controlling cube movement through player controls

Controlling object look-at behavior

Controlling object-to-object movements (seek, flee, follow at a distance)

Controlling object group movement through flocking

Firing objects by instantiation with forward velocity

Finding a random spawn point

Finding the nearest spawn point

Following waypoints in a sequence

Managing object behavior with states

Managing complex object behavior with the state pattern

Improving Games with Extra Features and Optimization

Introduction

Pausing the game

Implementing slow motion

Implementing 3D stereography with polarized projection

Preventing your game from running on unknown servers

Identifying performance "bottlenecks" with code profiling

Reducing the number of objects by destroying objects at a "death" time

Reducing the number of enabled objects by disabling objects whenever possible

Improving efficiency with delegates and events (and avoiding SendMessage!)

Executing methods regularly but independent of frame rate with coroutines

Spreading long computations over several frames with coroutines

Caching, rather than component lookups and "reflection" over objects

Taking Advantage of Unity Pro

Introduction

Dynamically focusing objects with Depth of Field

Creating a rearview mirror

Playing videos inside a scene

Simulating underwater ambience with audio filters

Loading and playing external movie files

Index