flyBoxController.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { _decorator, Component, Node, Prefab, instantiate } from 'cc';
  2. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  3. import { g } from '../Data/g';
  4. import { FlyTreasureChest } from './FlyTreasureChest';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('FlyBoxController')
  7. export class FlyBoxController extends Component {
  8. @property({ tooltip: "飞行宝箱父级", type: Node })
  9. public bg: Node;
  10. public starTime = 0;
  11. start() {
  12. this.starTime = Date.now();
  13. }
  14. async update() {
  15. if (g.gameData.flyBoxTimes == 0 || g.userData.lv < 3) {
  16. return;
  17. }
  18. // if (Date.now() - this.starTime >= 1000) {
  19. if (Date.now() - this.starTime >= g.gameData.flyBoxIntervalTime) {
  20. this.starTime = Date.now();
  21. g.gameData.flyBoxIntervalTime = 1000 * 60 * 2;//宝箱未领取,出现时间间隔改为两分钟
  22. this.addFlyBox();
  23. }
  24. }
  25. public async addFlyBox() {
  26. let box = await ResourcesUtils.load<Prefab>("Prefabs/飞行宝箱", null, this.node);
  27. var boxNode = instantiate(box);
  28. boxNode.parent = this.bg;
  29. let flyTreasureChest = boxNode.getComponent(FlyTreasureChest);
  30. flyTreasureChest.setData();
  31. }
  32. }