timer.ts 909 B

123456789101112131415161718192021222324252627282930
  1. import { _decorator, Component, Node, Label, find } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. import {
  4. param
  5. } from './loadData';
  6. @ccclass('timer')
  7. export class timer extends Component {
  8. public static time: number = param.levelTime;// 3 * 60;//默认三分钟生长周期
  9. public static isStart: boolean = false;
  10. start() {
  11. if (timer.isStart) {
  12. this.schedule(function callback() {
  13. if (timer.time <= 0) {
  14. this.node.getComponent(Label).string = ""
  15. this.node.parent.active = false;
  16. }
  17. else {
  18. if (timer.time > 0) {
  19. this.node.getComponent(Label).string = "倒计时:" + timer.time + "秒"
  20. }
  21. }
  22. timer.time--;
  23. }, 1);
  24. }
  25. }
  26. update(deltaTime: number) {
  27. }
  28. }