Unity 2D点击事件、碰撞

1.事件封装
定义脚本,实现事件相关接口即可

public class GameInputEvent2D : MonoBehaviour,IDragHandler,IBeginDragHandler,IEndDragHandler,IPointerClickHandler,IPointerDownHandler, IPointerUpHandler

2.点击对象必须要添加BoxCollider2D脚本

3.摄像机上必须添加Physics2DRaycaster脚本

4.GameInputEvent2D 事件必须添加在挂载Physics2DRaycaster的对象及其父类身上。

5.如果要有碰撞或者触发器回调,碰撞其中之一要添加Rigidbody2D脚本,且不能设置为静态的。

猜你喜欢

转载自blog.csdn.net/lcl20093466/article/details/129025879