12345678910111213141516171819202122232425262728293031323334353637 |
- import { _decorator, CircleCollider2D, Collider, Collider2D, Component, Contact2DType, ERigidBody2DType, ICollisionEvent, IPhysics2DContact, Node, PhysicsSystem2D, RigidBody2D, Vec2, Vec3 } from 'cc';
- import { EventManager } from '../EventManager';
- const { ccclass, property } = _decorator;
- @ccclass('Role')
- export class Role extends Component {
- rigidBody: any;
- public start() {
- let collider = this.getComponent(Collider2D);
- if (collider) {
- collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
- }
- }
- onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
- // 只在两个碰撞体开始接触时被调用一次
- switch (otherCollider.node.name) {
- case 'Top':
- case 'Bottom':
- case 'dici':
- EventManager.instance.et.emit(EventManager.EventType.Cut_haert);
- break;
- default:
- break;
- }
- }
- }
|