Game Development Reference
In-Depth Information
116 //Is this weapon. So equip
117 IsEquipped = true;
118
119 //Show default sprite
120 DefaultSprite.enabled = true;
121
122 //Activate Can Fire
123 CanFire = true;
124
125 //Send weapon change event
126 GameManager.Notifications.PostNotification(this, "WeaponChange");
127
128 //Weapon was equipped
129 return true;
130 }
131 //------------------------------------------------
132 //Weapon change event - called when player changes weapon
133 public void WeaponChange(Component Sender)
134 {
135 //Has player changed to this weapon?
136 if(Sender.GetInstanceID() == GetInstanceID()) return;
137
138 //Has changed to other weapon. Hide this weapon
139 StopAllCoroutines();
140 gameObject.SendMessage("StopSpriteAnimation", 0, SendMessageOptions.
DontRequireReceiver);
141
142 //Deactivate equipped
143 IsEquipped = false;
144
145 foreach(SpriteRenderer SR in WeaponSprites)
146 SR.enabled = false;
147 }
148 //------------------------------------------------
149 }
Before going further, be sure to implement both weapon classes into your project and take stock
over just how far we've come. Figure 6-19 shows the completed project up and running with weapon
functionality! Remember, the completed project for this chapter can be found in the topic companion
files at Chapter06/End .
 
Search WWH ::




Custom Search