Range is_action_pressed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kritou

I need to make an item that will disappear when you click on it, but if you write like this:

func _input(event):
if event.is_action_pressed(“my_action”):
queue_free()

then it will be collected from anywhere on the map. Please rewrite this code so that the button works only next to this item

:bust_in_silhouette: Reply From: Gluon

You will need something to assign the item you want to delete.

For instance if you add an area2d around the item and then something, like a player sprite or something else, enters this area2d you can have some code which says if it is in the area and the button is pressed then delete it. So it isnt as simple as just write some code, you need to think about how you are going to logically identify the item in your type of game.