count_time_start.ts 728 B

123456789101112131415161718192021222324
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('count_time_start')
  4. export class count_time_start extends Component {
  5. @property(Node) lab_time:Node = null
  6. private count:number = 0;
  7. public startGame(num:number,cb:Function){
  8. this.count = num
  9. this.lab_time.getComponent(Label).string = this.count + ""
  10. this.lab_time.active = true
  11. this.schedule(()=>{
  12. if(this.count<=0){
  13. cb()
  14. this.lab_time.active = false
  15. this.unscheduleAllCallbacks()
  16. }
  17. this.lab_time.getComponent(Label).string = this.count + ""
  18. this.count--;
  19. },1)
  20. }
  21. }