import { _decorator, Component, director, instantiate, Node, Prefab, UITransform, Vec3 } from 'cc'; import { GameData } from './GameData'; const { ccclass, property } = _decorator; @ccclass('MainScene') export class MainScene extends Component { @property(Prefab) countDown:Prefab; speed:number = 0; boss:Node = null; countDownTS:any = null; protected onLoad(){ //let gameData = instantiate(GameData); this.speed = GameData.speed; } start() { let countDown = instantiate(this.countDown); this.node.addChild(countDown); //获取倒计时预制体脚本 this.countDownTS = countDown.getComponent("CountDown"); this.boss = this.node.getChildByName("boss_05_normal"); } update(deltaTime: number) { //倒计时结束,游戏开始 if(this.countDownTS.isOver){ let x =this.boss.getPosition().x; x += this.speed * deltaTime; if(x >= (this.node.getComponent(UITransform).contentSize.width)/2){ this.speed = 0; }else{ this.boss.setPosition(new Vec3(x,this.boss.getPosition().y)); } } } }