0
Answered

Ammo count variable ?

NeoprodGame 10 months ago in Shooter updated by Marti (Lead Developer) 9 months ago 3

I would like to display the number of ammunition of each type (gun, assault riffle, ect ..) all the time. How can I retrieve the number of ammunition to display them even when the weapon is not equipped?

Unity version:
2018+
Game Creator version:
Last

Answer

Answer
Answered

Hi Neoprod!

Fairly easy. You can use the "Ammo UI" component for that. Simply add this component to where it makes sense (probably in a UI game object) and select the target Character you want to track ammo from (Player, most likely).

You'll need one "Ammo UI" component per each tracked ammo.The Ammo asset has a "Unique Name" property at the top. This is a unique identifier that identifies the ammo. For example, the Revolver's bullets ammo asset may have an ammo identified by "ammo-revolver". You'll need top copy this text and place it in the Ammo UI current ammo id property. This will tell which ammo type to track.

All that's left to do is drop in the Text component you'll use to display the ammo count. Every element is optional, so no need to fill them all. For example, if you want to just display the total amount of bullets you have in your gun's clip, drop a Text component onto the "Ammo In Clip" field.

Cheers!

Answer
Answered

Hi Neoprod!

Fairly easy. You can use the "Ammo UI" component for that. Simply add this component to where it makes sense (probably in a UI game object) and select the target Character you want to track ammo from (Player, most likely).

You'll need one "Ammo UI" component per each tracked ammo.The Ammo asset has a "Unique Name" property at the top. This is a unique identifier that identifies the ammo. For example, the Revolver's bullets ammo asset may have an ammo identified by "ammo-revolver". You'll need top copy this text and place it in the Ammo UI current ammo id property. This will tell which ammo type to track.

All that's left to do is drop in the Text component you'll use to display the ammo count. Every element is optional, so no need to fill them all. For example, if you want to just display the total amount of bullets you have in your gun's clip, drop a Text component onto the "Ammo In Clip" field.

Cheers!

I understood this system, its reassures me. But unfortunately I did not find or place my AmmoID. This one being in private in the script, I duplicate AmmoUI, I rename it AmmoUIinventory. And I can modify the script to display the ammunition available in the inventory. In this way I manage to display all the ammunition at the same time, without this one changing each time I equip a weapon. Thank you for your indication which put me on the right path.

AmmoID is private? Hmm it shouldn't be. I'm opening a ticket and have a read-only access from outside :-) Cheers!