self-plane.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { _decorator, Component, Node, input, Input, EventTouch, Collider, ITriggerEvent } from 'cc';
  2. import { constant } from '../framework/constant';
  3. const { ccclass, property } = _decorator;
  4. // 未使用
  5. @ccclass('self_plane')
  6. export class self_plane extends Component {
  7. // @property
  8. // public speed = 1;
  9. start() {
  10. // input.on(Input.EventType.TOUCH_START, this._touchStart, this);
  11. // input.on(Input.EventType.TOUCH_MOVE, this._touchMove, this);
  12. }
  13. onEnable() {
  14. const collider = this.getComponent(Collider)
  15. collider.on('onTriggerEnter', this._onTriggerEnter, this)
  16. }
  17. onDisable() {
  18. const collider = this.getComponent(Collider)
  19. collider.off('onTriggerEnter', this._onTriggerEnter, this)
  20. }
  21. private _onTriggerEnter(event: ITriggerEvent) {
  22. console.log('玩家');
  23. const collisionGroup = event.otherCollider.getGroup();
  24. if (collisionGroup === constant.CollisionType.ENEMY_PLANE) {
  25. // 敌机或敌机子弹
  26. console.log('reduce blood');
  27. }
  28. }
  29. // update(deltaTime: number) {
  30. // }
  31. // _touchMove(event: EventTouch) {
  32. // const delta = event.getDelta();
  33. // let pos = this.node.position;
  34. // // x 上下, z 左右
  35. // // this.node.setPosition(pos.x - 0.01 * this.speed * delta.x, pos.y, pos.z - 0.01 * this.speed * delta.y)
  36. // this.node.setPosition(pos.x + 0.01 * this.speed * delta.y, pos.y, pos.z + 0.01 * this.speed * delta.x)
  37. // }
  38. }