通过窗口获取鼠标当前坐标
var mouse_position:Vector2 = get_viewport().get_mouse_position()
print(mouse_position.x)
print(mouse_position.y)
通过内置虚函数获取鼠标点击事件
func _input(event) :
if event is InputEventMouseButton :
if event.button_index == MOUSE_BUTTON_LEFT :
if event.pressed :
print("鼠标左键点击事件")
else:
print("鼠标左键释放事件")
if event.button_index == MOUSE_BUTTON_RIGHT :
if event.pressed :
print("鼠标右键点击事件")
else:
print("鼠标右键释放事件")
if event.button_index == MOUSE_BUTTON_MIDDLE :
print("鼠标中键点击事件")
if event.button_index == MOUSE_BUTTON_WHEEL_UP :
print("鼠标滚轮向上滚动事件")
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN :
print("鼠标滚轮向下滚动事件")
获取