0 votes

Anyone know how to do this in Godot c #.
I want to detect the mouse input as follows, but I can't find the solution.

Alguien sabe hacer esto en Godot c#.
osea quiero detectar el input del mouse de la siguiente forma,pero no puedo encontrar la solución.

In Godot Gdscript working
func input(event):
if event is InputEventMouseButton:
if event.button
index == BUTTON_RIGHT and event.pressed:
pass


In Godot c# no working

public override void _Input(InputEvent @event)
{
if(@event is InputEventMouseButton evento)

         if(evento.Pressed && evento.ButtonIndex == BUTTON_RIGHT)
         {

         }

}

https://drive.google.com/file/d/1xeX_psvfk6WKNqdTst9gUHg8VcJtVXBE/view?usp=sharing
https://drive.google.com/open?id=1MQvnAMdZ2fPBMJwiLn7rC_aaAOZht6Pm

asked Mar 9 in Projects by Ariel Gimenez (24 points)
edited Mar 9 by Ariel Gimenez

1 Answer

+1 vote
Best answer

In C#, global constants are stored in an enum.
Try with ButtonList.Right: https://godotsharp.net/api/3.2.0/Godot.ButtonList/

answered Mar 9 by Zylann (26,143 points)
selected Mar 10 by Ariel Gimenez

I didn't know that page with the Godot c # API, thanks for sharing it.
Now the problem is that the comparison cannot be made.
if ("event.ButtonIndex == ButtonList.Right")
Also thank you very much.

regards

Yeah C# is picky, and the Godot API isn't very idiomatic to C#. So you have to cast it to int:

if (event.ButtonIndex == (int)ButtonList.Right)

Thank you very much, now it worked.
 

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 How to use this Q&A? before posting your first questions.