import { _decorator, Component, Node, Prefab, instantiate } from 'cc'; import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils'; import { g } from '../Data/g'; import { FlyTreasureChest } from './FlyTreasureChest'; const { ccclass, property } = _decorator; @ccclass('FlyBoxController') export class FlyBoxController extends Component { @property({ tooltip: "飞行宝箱父级", type: Node }) public bg: Node; public starTime = 0; start() { this.starTime = Date.now(); } async update() { if (g.gameData.flyBoxTimes == 0 || g.userData.lv < 3) { return; } // if (Date.now() - this.starTime >= 1000) { if (Date.now() - this.starTime >= g.gameData.flyBoxIntervalTime) { this.starTime = Date.now(); g.gameData.flyBoxIntervalTime = 1000 * 60 * 2;//宝箱未领取,出现时间间隔改为两分钟 this.addFlyBox(); } } public async addFlyBox() { let box = await ResourcesUtils.load("Prefabs/飞行宝箱", null, this.node); var boxNode = instantiate(box); boxNode.parent = this.bg; let flyTreasureChest = boxNode.getComponent(FlyTreasureChest); flyTreasureChest.setData(); } }