(Updated for RFPS 1.23 – 1.24)
This page contains an unofficial “how-to” for using the new Unity UI to show ammo text in Azuline Studios’ Realistic FPS Prefab (RFPS). (Realistic FPS Prefab is developed by Azuline Studios.)
1. Add a world space canvas to each gun. World space means it’s rooted to a position on the gun, rather than overlaying the screen in screen space. You can use a screen space canvas if you don’t want it positioned on the gun. If you don’t want to show an ammo count (such as for a knife or flashlight), don’t add a canvas to the weapon.
2. Add a Text element to the canvas.
3. The RFPS player prefab loads a HUD prefab named AmmoText that contains two GUITexts, one for the main counter text and a child for the drop shadow. Set their colors to 0 to make them invisible.
4. Instead, AmmoText should update the Text element on your weapon’s canvas. To do this, it needs a reference to the Text element. Add a public variable for it to AmmoText.cs. Then, in the Start() and SwitchWeapon() methods in WeaponBehaviour.cs, set AmmoText’s Text element. In AmmoText.cs’s Update() method, set the Text element’s text value to ammoGui.ToString().
So in AmmoText.cs, add these lines:
Line 30 in RFPS 1.23+, Line 19 in RFPS 1.21-1.22:
public UnityEngine.UI.Text uiText = null;
Line 51 in RFPS 1.23+, Line 39 in RFPS 1.21-1.22:
if (uiText != null) uiText.text = ammoGui.ToString() + (showMags ? " / " + ammoGui2.ToString() : string.Empty);
5. In WeaponBehavior.cs, add these lines:
Start method – line 715 in RFPS 1.23+, line 257 in RFPS 1.22, line 234 in RFPS 1.21:
if (AmmoText1 != null) AmmoText1.uiText = GetComponentInChildren<UnityEngine.UI.Text>();
OnEnable method – line 343 in RFPS 1.22, line 319 in RFPS 1.21: (for RFPS 1.23, see below)
if (AmmoText1 != null) AmmoText1.uiText = GetComponentInChildren<UnityEngine.UI.Text>();
For RFPS 1.23+, you’ll need to add an OnEnable method. Line ~680 (above the void Start() method):
void OnEnable() { if (AmmoText1 != null) AmmoText1.uiText = GetComponentInChildren<UnityEngine.UI.Text>(); }
More Goodies
- Proof-of-concept grenade throwing: RFPS_Grenade unitypackage