BulletBase.ts 755 B

12345678910111213141516171819202122232425262728293031
  1. import { _decorator, Component } from 'cc';
  2. import { GunBase } from './GunBase';
  3. import { PoolManager } from '../../core/manager/PoolManager';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('BulletBase')
  6. export class BulletBase extends Component {
  7. public isDead: boolean = false;
  8. //枪的数据 在gunBase中
  9. public gunBase: GunBase = null!;
  10. //子弹自动回收的时间5s
  11. private recycleTime: number = 3;
  12. constructor(){
  13. super();
  14. this.isDead = false;
  15. }
  16. start() {
  17. this.scheduleOnce(this.autoRecycle.bind(this),this.recycleTime);
  18. }
  19. public autoRecycle(){
  20. if(!this.isDead){
  21. this.isDead = true;
  22. PoolManager.putNode(this.node);
  23. }
  24. }
  25. }