I'm working on a game, and I'm trying to make a eating feature, I got the player's part down for the most part, but the food's script does not want to work it seems. I've tried so many different ways to make the food disappear once it's substance has reached 0 or less. sorry if the code below is hard to read, this is my first time making a game and my first time posting a question."eating food"+"yum!" are printed out each bite until the substance reaches 0 or less, then it prints out "eating food"+"food eaten"+"yum!" for each bite after that. Please let me know if there is a better way to do this
main
extends KinematicBody2D
func _on_FoodPH_eaten():
print("signal1")
food.visible = not get_node("Food").visible
food.queue_free()
food
func Eating():
Substance -= 1
print("eating food")
if Substance <= 0:
Eaten()
func Eaten():
emit_signal("eaten")
print("food eaten")
player
func _input(event):
if event.is_action_pressed("Bite"):
for body in $Player.get_overlapping_areas():
if body.is_in_group("Food"):
Food.Eating()
emit_signal ("Eat")
func _on_Player_Eat():
Hunger += 2
print("yum!")