// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class NewClass extends cc.Component { //建立倒數的變數:num num = 10; //建立目前文字label組件變數:label01 label01 = null; onLoad () { //取得目前節點node裡面的組件component(Label) this.label01 =this.node.getComponent(cc.Label); //開啟計時器 this.schedule(this.timer, 1); } //時間到了就會執行timer()函數,時間到了,就不斷重複執行 timer() { //每次數字num減一 this.num -=1; //如果num小於0,就停止計時器 if(this.num <=0) { this.unschedule(this.timer); } //在組件label的屬性string顯示最新數字 this.label01.string = this.num; } // start () { // } // update (dt) {} }