Game Development Reference
In-Depth Information
Figure 6-18. Preparing to create weapon-change functionality. Notice that I've hidden all sprite renderers for the gun, to prevent
multiple frames showing at the same time. The PlayerController and Weapon classes handle which sprites should be shown,
and when
To implement weapon changing for the PlayerController, consider the revised controller class in
Listing 6-7, with changes highlighted in bold. Remember, the PlayerController class was first
created in the previous chapter. Comments follow.
Listing 6-7. PlayerController.cs: Revised PlayerController Class with Weapon Switching Implemented
001 //------------------------------------------------
002 using UnityEngine;
003 using System.Collections;
004 using System.Collections.Generic;
005 //------------------------------------------------
006 public class PlayerController : MonoBehaviour
007 {
008 //------------------------------------------------
009 //Amount of cash player should collect to complete level
010 public float CashTotal = 1400.0f;
011
012 //Amount of cash for this player
013 private float cash = 0.0f;
014
015 //Reference to transform
016 private Transform ThisTransform = null;
017
018 //Respawn time in seconds after dying
019 public float RespawnTime = 2.0f;
020
021 //Player health
022 public int health = 100;
023
024 //Get Mecanim animator component in children
025 private Animator AnimComp = null;
026
 
Search WWH ::




Custom Search