如何在Godot 4中检查Area2D上的鼠标点击?

huangapple go评论70阅读模式
英文:

How to check for mouse click on Area2D in Godot 4?

问题

我如何在Area2D的脚本中检测鼠标点击/鼠标事件?我是否使用func _process(delta)函数?假设我有一个名为area的2D区域。那么脚本应该是什么样的?我想要像这样的效果:

extends Area2D

func _process(delta):
    if mouse_touching && mouse_left_down:
        print("clicked on object")
英文:

How do I detect mouse clicks/mouse events in an Area2D's script? Do I use the func _process(delta) function? Let's say I have an area 2D called area. So what should the script be like? I want something like this:

extends Area2D


func _process(delta):
    if mouse_touching && mouse_left_down:
        print("clicked on object")

答案1

得分: 1

如果你的 Area2D 具有 input_pickable,那么当用户点击它时,它将收到对 _input_event 的调用。

英文:

If your Area2D has input_pickable then it will get a call to _input_event when the user clicks it.

huangapple
  • 本文由 发表于 2023年6月1日 11:16:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378457.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定