1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { _decorator, Button, Component, Label, math, Node } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('test')
- export class test extends Component {
- @property(Node) btn_add_50;
- @property(Node) btn_add_500;
- @property(Node) btn_add_5000;
- @property(Node) lab_number;
- private all_num:number = 100;
- protected start(): void {
- this.btn_add_50.on(Node.EventType.TOUCH_END,()=>{
- this.addCoinNumber(100);
- })
- this.btn_add_500.on(Node.EventType.TOUCH_END,()=>{
- this.addCoinNumber(500);
- })
- this.btn_add_5000.on(Node.EventType.TOUCH_END,()=>{
- this.addCoinNumber(5000);
- })
- }
- addCoinNumber(num:number){
- let cur_num = 0;
- let bei = num/100;
- let schedule_num = 0.01/bei;
- console.log("schedule_num",bei)
- this.schedule(()=>{
- cur_num+=1*bei;
- cur_num = Math.floor(cur_num);
- if(cur_num>=num){
- this.lab_number.getComponent(Label).string = this.all_num+num +"";
- this.unscheduleAllCallbacks()
- return
- }
- this.lab_number.getComponent(Label).string = this.all_num+cur_num +"";
- },schedule_num)
- }
- }
|