GunComponent.ts 698 B

12345678910111213141516171819202122232425
  1. import { _decorator, Animation, AnimationClip, AnimationState, Component, Node } from 'cc';
  2. import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
  3. import { GameEvent } from '../Enum/GameEvent';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('GunComponent')
  6. export class GunComponent extends Component {
  7. gunAnimation: Animation = null!;
  8. start() {
  9. this.gunAnimation = this.node.getComponent(Animation)!;
  10. EventDispatcher.instance.on(GameEvent.EVENT_PLAY_GUN_ANIMATION,this.playGunAnimation,this);
  11. }
  12. playGunAnimation(){
  13. if(!this.gunAnimation){
  14. return;
  15. }
  16. this.gunAnimation.play();
  17. }
  18. }