GunComponent.ts 676 B

1234567891011121314151617181920212223
  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. protected onLoad(): void {
  9. this.gunAnimation = this.node.getComponent(Animation)!;
  10. }
  11. start() {
  12. EventDispatcher.instance.on(GameEvent.EVENT_PLAY_GUN_ANIMATION,this.playGunAnimation,this);
  13. }
  14. playGunAnimation(){
  15. this.gunAnimation.play();
  16. }
  17. }