Displaying current ammo amount

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dang_

Hi, Im just wondering if there is a simple way for you to display the ammo you have. For my game, you collect it along the way and I want to be able to let the player see how much they have. Any advice and code is welcome thank you

Depending upon your setup, you may only need to put a Label on the screen which updates with the player’s bullet count. When bullets are collected, update this number (usually through a signal to a function).

Ertain | 2020-10-20 15:10

how would I code it ??

dang_ | 2020-10-21 06:07

:bust_in_silhouette: Reply From: Asthmar

Add an area2d to your bullet

create a label and give it a script

Connect the area entered signal to label

In the label script, create a variable

var bullets_num

func _on_area_body_entered(body):
if area is_in_group(“player”):
bullets_num += 1

under the process function

text = bullets_num