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

in Engine by (25 points)
edited by

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/

by (27,593 points)
selected by

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.
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 webmaster@godotengine.org with your username.