Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Tato64 |
Hello all, thanks for clicking on my question.
Basically, im making a top-down 2D, think of the style of “Hotline miami”.
I want to be able to pick up weapons with right click.
Basically it works like this:
Character has an area2D, weapon on the ground has an area2D, character has a signal to detect the weapon’s area, player right clicks: weapon on the ground is deleted, character sprite changes (and a weapon node is added to the character, but this isnt in the code yet)
Here’s the relevant code:
var pistol = preload("res://personaje.png")
var in_pickup_area = false
var sprite_texture
var pickup_area
func _on_Area2D_area_entered(area):
print(area.name)
if area.name == "Pistol (pickup)":
in_pickup_area = true
sprite_texture = pistol
var pickup_area = area
func _on_Area2D_area_exited(area):
if in_pickup_area:
if area == pickup_area:
in_pickup_area = false
pickup_area = null
func _process(_delta):
if Input.is_action_just_pressed("rclick"):
if in_pickup_area and pickup_area != null:
$Sprite.set_texture(sprite_texture)
pickup_area.queue_free()
in_pickup_area = false
pickup_area = null
When i stand on the weapon, the console prints “Pistol (pickup)” so it is detecting correctly, but right clicking does absolutely nothing
Please help!
Thanks in advance!