Game Development Reference
In-Depth Information
131 //------------------------------------------------
132 //Function called when player dies
133 public IEnumerator Die()
134 {
135 //Disable input
136 GameManager.Instance.InputAllowed = false;
137
138 //Trigger death animation if available
139 if(AnimComp) AnimComp.SetTrigger("ShowDeath");
140
141 //Wait for respawn time
142 yield return new WaitForSeconds(RespawnTime);
143
144 //Restart level
145 Application.LoadLevel(Application.loadedLevel);
146 }
147 //------------------------------------------------
148 void Update()
149 {
150 //Build screen rect on update (in case screen size changes)
151 ScreenRect.x = ScreenRect.y = 0;
152 ScreenRect.width = Screen.width;
153 ScreenRect.height = Screen.height;
154
155 if(Input.GetKeyDown(KeyCode.Period))
156 EquipNextWeapon();
157 }
158 //------------------------------------------------
159 //Equip next available weapon
160 public void EquipNextWeapon()
161 {
162 //No weapon found yet
163 bool bFoundWeapon = false;
164
165 //Loop until weapon found
166 while(!bFoundWeapon)
167 {
168 //Get next weapon
169 ActiveWeapon = ActiveWeapon.NextWeapon;
170
171 //Activate weapon, if possible
172 ActiveWeapon.gameObject.SendMessage("Equip", ActiveWeapon.Type);
173
174 //Is successfully equipped?
175 bFoundWeapon = ActiveWeapon.IsEquipped;
176 }
177 }
 
Search WWH ::




Custom Search