–2 votes

I have many "Pawn", "Pawn1"... scene instances in my game, i'd like to be able to select only one at once with a mouse left click. Right click would also be deselecting the one.
But when i left click on one and then another it select the second while letting the first selected.
Right click does unselect all as intended.

func _on_Area2D_mouse_entered():
    selectable = true

func _on_Area2D_mouse_exited():
    selectable = false

func _input(event):
    if event is InputEventMouseButton and event.button_index == 1 and selectable:
        selected = true

    if event is InputEventMouseButton and event.button_index == 2:

func _on_Area2D_unselect():
    selected = false

EDIT : Actually while trying to explain the problem I found the solution, i had to do this :

if event is InputEventMouseButton and event.button_index == 1:
    if selectable:
        selected = true

But can someone explain to me why would the conditions prevent the signal to be propagated to other instances that (i think) should just execute the received signal in onArea2D_unselect() ?

in Engine by (10 points)
edited by

1 Answer

0 votes

Pawn? What its mean?

by (14 points)

It's only an area2D, named "Pawn" (like in chess).

The exemple code is cleaned with the actual Godot class if that was what caused the downvotes...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.