// 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 { onLoad () { //啟動計時器 this.schedule(this.timer, 0.01); } timer() { this.node.y += 40; //飛出的子彈,如果沒有銷毀,就會在記憶體儲存很多沒有用的子彈資料 if(this.node.y >= 2000) { //停止計時器 this.unschedule(this.timer); //銷毀子彈物件 this.node.destroy(); //結束這個函數 return; } } // update (dt) {} }