Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

how do i make a ammo counter

So basically i am making a shooter game and after folowing brackeys gun tutorials and now im wondring how to make an ammo counter

Answers

  • Make an int for current ammo and max ammo. In your start or awake set current ammo to max ammo. wrap your shoot code in an if statement to see if the current ammo value is over 0. in your shoot code decrement the current ammo. add a function to reload when you hit a button( use coroutines so you can delay it). . Add a bool to check if you are reloading, set it to false by default. In the if statement that wraps the shoot code check to see if that is false. in the reload function set reloading to true than after your final return set reloading bool to false and reset ammo to max ammo. Simply reference text in your scene and set the .text component equal to your current ammo.

  • You need to set an value for "ammoCount". This represents your current ammo.


    Now you need to make a method for shooting in which you use your ammo count as an argument. decrease it by 1 and return the value to "ammoCount".


    Download SoloLearn if you dont know about methods or watch the tutorials on yt.

    Greetings, Islu.

Sign In or Register to comment.