// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import EventName, { PopType } from "../EventName/EventName"; import LocalData from "../LocalData"; import MyComponent from "../Template/MyComponent"; const { ccclass, property } = cc._decorator; @ccclass export default class Gold extends MyComponent { Label: cc.Label = null onLoad(): void { this.regEvent(EventName.changeGold, this.UpdataGold, this) } start() { let add = this.node.getChildByName("add") this.Label = this.node.getChildByName("Label").getComponent(cc.Label) switch (cc.director.getScene().name) { case 'Game': add.active = false break; case 'Hall': add.active = true break; default: break; } this.Label.string = LocalData.getInstance().getGold().toString() } UpdataGold() { this.Label.string = LocalData.getInstance().getGold().toString() } ClickGold() { cc.log('ClickGold') //提示看广告拿金币 let temp: PopType = new PopType() temp.string = '看广告拿金币' temp.Title = '提示' temp.OK = () => { this.OpenAD() } temp.Fail = () => { } this.Pop(temp) } // update (dt) {} }