test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { _decorator, Button, Component, Label, math, Node } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('test')
  4. export class test extends Component {
  5. @property(Node) btn_add_50;
  6. @property(Node) btn_add_500;
  7. @property(Node) btn_add_5000;
  8. @property(Node) lab_number;
  9. private all_num:number = 100;
  10. protected start(): void {
  11. this.btn_add_50.on(Node.EventType.TOUCH_END,()=>{
  12. this.addCoinNumber(100);
  13. })
  14. this.btn_add_500.on(Node.EventType.TOUCH_END,()=>{
  15. this.addCoinNumber(500);
  16. })
  17. this.btn_add_5000.on(Node.EventType.TOUCH_END,()=>{
  18. this.addCoinNumber(5000);
  19. })
  20. }
  21. addCoinNumber(num:number){
  22. let cur_num = 0;
  23. let bei = num/100;
  24. let schedule_num = 0.01/bei;
  25. console.log("schedule_num",bei)
  26. this.schedule(()=>{
  27. cur_num+=1*bei;
  28. cur_num = Math.floor(cur_num);
  29. if(cur_num>=num){
  30. this.lab_number.getComponent(Label).string = this.all_num+num +"";
  31. this.unscheduleAllCallbacks()
  32. return
  33. }
  34. this.lab_number.getComponent(Label).string = this.all_num+cur_num +"";
  35. },schedule_num)
  36. }
  37. }