Godot控件响应鼠标点击事件
作者:互联网
以TextureRect控件为例,其它控件同理:
// Confirm dialog
// Created by nwhasd
// 2021/9/15
// MIT license
using Godot;
public class Node2D : TextureRect
{
public override void _Ready()
{
// 绑定gui输入事件
Connect("gui_input", this, nameof(OnGuiInput));
}
// 输入事件回调函数
private void OnGuiInput(InputEvent inputEvent)
{
if (inputEvent is InputEventMouseButton mouseInput)
{
if (mouseInput.ButtonIndex == (int) Godot.ButtonList.Left)
{
if (mouseInput.IsPressed())
GD.Print("鼠标左键按下");
else
GD.Print("鼠标左键抬起");
}
else if (mouseInput.ButtonIndex == (int) Godot.ButtonList.Right)
{
if (mouseInput.IsPressed())
GD.Print("鼠标右键按下");
else
GD.Print("鼠标右键抬起");
}
}
}
}
标签:控件,Godot,鼠标,GD,Print,mouseInput 来源: https://blog.csdn.net/u013404885/article/details/120307375