Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Shlopynoobnoob |
I made a coin scene and when the player collide with it the coin disappears and the score goes higher but it’s not working.
here is the coin code:
extends Area2D
signal e_grabbed
func _on_coin_body_entered(body):
if body.name == "player":
emit_signal("e_grabbed")
queue_free()
and this is the main scene code:
func spawn():
var coin_scene = load("res://scenes/coin.tscn")
randomize()
var coin = coin_scene.instance()
var random = Vector2(rand_range(30,230),-4)
coin.set_position(random)
coin.connect("e_grabbed", self, "_on_e_grabbed")
$coins.add_child(coin)
func _on_e_grabbed():
print("grgrg")
it doesn’t print ‘grgrg’
Did you try adding a debugger to the _on_coin_body_entered(body)
function and checking if the body entering is actually what you expect it to be? For example, you might have a player but the name is not matching ‘player’.
tastyshrimp | 2019-12-19 22:12