Game Development Reference
In-Depth Information
trivial optimization, hardly worth pursuing perhaps, but the aggregate improvements this can make
over time, across many possible transform calls, can be considerable. So I recommend using
Cached Transforms wherever possible; they're quick and easy to implement. We'll be using them
here, for creating Billboards.
Billboards and Rotation
For a sprite to truly act as a Billboard, it needs to continually rotate (around the Y axis) to face the
game camera, wherever it may be in the scene (see Figure 4-4 ). We don't need to worry about
Z and X rotations for CMOD, since the player cannot crouch, jump, or roll over to see the sprite from
underneath or above. Using Cached Transforms, we can achieve this rotation in only a few lines of
code. (Listing 4-4 shows the complete Billboard class. Comments follow, and I recommend reading
the code sample through a few times—it uses many different concepts that we'll explore.)
Figure 4-4. CMOD sprites will need to rotate around the Y axis (YAW)
Listing 4-4. Completing the Billboard Class
01 using UnityEngine;
02 using System.Collections;
03
04 public class Billboard : MonoBehaviour
05 {
06 private Transform ThisTransform = null;
07
08 // Use this for initialization
09 void Start ()
10 {
11 //Cache transform
 
Search WWH ::




Custom Search