Display actual number of bullets

This should be an easy one- While using the new GUI, how would I display the exact number of bullets/torpedos, etc in a slider? Currently, it works, but there are too many to start out with.

Hold on a second. First you talked about bullets, then battery, and now torpedos? Just call it ammo, it’s less confusing :slight_smile:

using UnityEngine.UI;

public class PlayerGUI : MonoBehaviour {

	public Text text_ammo;
        public int ammo;
        public int ammo_max;
        

	public void UpdateAmmoText() {

		text_ammo.text = ammo.ToString() + "/" + ammo_max.ToString();
	}

}

You have to drag you Text UI Object into the text_ammo slot in the inspector. Set the ammo and ammo_max however you want, and call the UpdateAmmoText option whenever one of the values change (Firing, reloading).

A slider is possible as well of course, check the Scripting API for the relevant variables.