I'm working on a game, and I'm trying to make an 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 many different ways to make the food disappear once it's substance has reached 0 or less.
print "signal1" is the only one that doesn't activate at any time, and there are no errors.
The (top) main script is attached to the parent node of both the food and player scripts. "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.
The (mid) food script is attached to a kinematicbody2D, and the (bottom) player script is attached to another separate kinematicbody2D node.
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!")