**extends Area2D
var playerHasTouched = false
var canReload = false
var hasShot = false
var reloaded = false
static var bulletCount = 10
@export var bullet_count : Label
func _input(event):
if Input.is_action_just_pressed("Shoot") and canReload == false and hasShot == false:
bulletCount -= 1
hasShot = true
await get_tree().create_timer(0.5).timeout
hasShot = false
bullet_count.text = "BULLET COUNT: " + str(bulletCount)
if bulletCount <= 0:
canReload = true
print("BOOL: " + str(canReload))
func _on_body_entered(body):
playerHasTouched = true
if bulletCount == 0 and canReload == true and playerHasTouched == true:
replenish()
elif playerHasTouched == false:
Reload.reloadAmmo = false
reloaded = false
print("This Worked!")
queue_free()
func replenish():
bulletCount += 10
Reload.reloadAmmo = true
hasShot = false
canReload = false
reloaded = true
bullet_count.text = "BULLET COUNT: " + str(bulletCount)
reloaded = false**
I need some help with this code. I made it so when you enter the body of the object, it adds 10 to the ammoCount. But when it does, and I click “shoot” it doesn’t go down. It just stays there.
sorry if it is messy.
It goes down before I reload. Which is fine. It’s supposed too.
Also, I am not looking for any feedback on why I coded the way I did or whether or not you think it’s weird that I have a cooldown for each time the text updates. I just need some help on WHY it doesn’t update after reloading.
**I just tried to make it like this :
**
Ammo Count -> -1 each time Shoot is pressed.
So when colliding with the Ammo :
Ammo Count -> 10 which is does.
but when I Shoot AGAIN :
Ammo Count = 10 it stays in place. I thought it would work.
Isaiah Sanchez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.