Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections; 3.
4. [RequireComponent(typeof(GeneralWeapon))]
5. public class AmmoDisplay : MonoBehaviour { 6.
7.
//Where to display data
8.
public TextMesh display;
9.
10.
//The weapon to display data for
11.
GeneralWeapon
weapon; 12.
13.
void Start () {
14.
weapon = GetComponent<GeneralWeapon>();
15.
}
16.
17.
void LateUpdate () {
18.
//Do not show if weapon is not in hand
19.
if(!weapon.inHand){
20.
display.text = "XXX";
21.
return;
22.
}
23.
24.
float reloadProgress = weapon.GetReloadProgress();
25.
//Show number of bullets and magazines remaining
26.
if(reloadProgress == 0){
27.
display.text = weapon.magazineSize + "/" +
28.
weapon.magazineCapacity + " (x" +
29.
weapon.magazineCount + ")";
30.
}
else {
31.
//If reloading, show reload progress
32.
int progress = (int)(reloadProgress * 100);
33.
display.text = "RLD " + progress + "%";
34.
}
Search WWH ::




Custom Search