Godot 3.2 Alpha1
节点结构
其中
clickable是个MeshInstance
负责显示模型,这个Demo的逻辑脚本也挂在了上面
Area就是Area
类型的CollisionObject
CollisionShape就是CollisionObject
所需的CollisionShape
Godot实现这个效果的思路非常清晰而且符合职责单一的原则:
MeshInstance
负责显示
CollisionObject
负责碰撞检测以及信号发送
CollisionShape
负责描述碰撞盒
代码:
extends MeshInstance
func _on_Area_input_event(camera, event, click_position, click_normal, shape_idx):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed == true:
_doSomething()
func _doSomething():
print("Hi Click")
然后把_on_Area_input_event
方法连接到Area的相应事件就可以了
小结
简单常用的功能