Grass.ts 603 B

123456789101112131415161718192021222324252627282930313233
  1. const {ccclass, property} = cc._decorator;
  2. import GameUtil from '../utils/util/GameUtil';
  3. @ccclass
  4. export default class Grass extends cc.Component
  5. {
  6. private index:number=0;
  7. public next=GameUtil.randomRange(60,500);
  8. protected update(dt: number): void {
  9. this.index++;
  10. if(this.index>this.next)
  11. {
  12. this.index=0;
  13. this.next=GameUtil.randomRange(600,1000);
  14. }
  15. if(this.index>this.next-5)
  16. {
  17. this.node.scale=1.2
  18. }
  19. else
  20. {
  21. this.node.scale=1;
  22. }
  23. }
  24. }