Godot Version
4.2.1 Stable
Question
I need some help with this code. I made it so when you enter the body of the object, it adds 10 to your ammoCount. But when it does, and I click “shoot” it doesn’t go down. It just stays there. Here’s the code:
extends Area2D
var playerHasTouched = false
var canReload = false
var hasShot = false
var reloaded = false
static var bulletCount = 10
@onready var bullet_count = $"../Player/Camera2D/Bullet Count"
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
bullet_count.text = "BULLET COUNT: " + str(bulletCount)
Reload.reloadAmmo = true
hasShot = false
canReload = false
reloaded = true
``` sorry if it is messy.