Game Development Reference
In-Depth Information
First-Person Capsule Mesh
Next, let's get to work on creating a general PlayerController.cs class for handling most high-level
player functionality. The first issue to address with this class concerns the player controllers. Both
the desktop and mobile First Person Controllers feature a renderable capsule mesh, which is both
visible in the Unity Editor and at runtime. Normally, the capsule mesh is not visible during gameplay,
but this is only because the controller camera is positioned in a specific way. In theory, the capsule
could be seen if reflective materials were used in the scene or if the camera were offset through
animation (and it will be later). There's nothing either in principle or practice to prevent the capsule
mesh from being seen, and normally we don't want it to be seen. So let's hide it at runtime using
a C# script, as opposed to disabling it in the editor. This lets us continue seeing the capsule mesh
in the editor at design time. To get started, create a PlayerController.cs file. This will be added
to each First Person Controller object—attached to the same object as the HeadBob script—the
object marked with the player tag (see Figure 5-13 ). This is important for later because this script
will also handle Player collision events with power-ups: specifically, cash allocation (see Listing 5-3;
comments follow).
Figure 5-13. Adding the PlayerController script to First Person Controller objects
Listing 5-3. PlayerController.cs: Disabling Capsule Meshes for First Person Controllers
01 //------------------------------------------------
02 using UnityEngine;
03 using System.Collections;
04 using System.Collections.Generic;
05 //------------------------------------------------
06 public class PlayerController : MonoBehaviour
07 {
08 //------------------------------------------------
 
Search WWH ::




Custom Search