本帖最后由 十二月雪景 于 2023-6-11 01:11 编辑
//方块位置
private _cubePos:Type.Vector;
//右侧点
private _rightPos:Type.Vector;
//左侧点
private _leftPos:Type.Vector;
//方块
private _cube:Core.GameObject;
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected async onStart(): Promise<void> {
this.useUpdate=true;
if(SystemUtil.isClient()){
this._cube=await Core.GameObject.asyncFind('1AFBA7B9');
this._cubePos=this._cube.worldLocation;
this._rightPos=(await Core.GameObject.asyncFind('292F1F5E')).worldLocation;
this._leftPos=(await Core.GameObject.asyncFind('15C2DFCD')).worldLocation;
const letfY= this._leftPos.y;
const orignalY= this._cubePos.y;
const rightY= this._rightPos.y;
const rightToOriginalTween=new TweenUtil.Tween({y:rightY})
.to({y:orignalY},3000)
.onUpdate((object)=>{
this._cube.worldLocation=new Type.Vector(this._cube.worldLocation.x,object.y,this._cube.worldLocation.z);
});
const leftToOriginalTween=new TweenUtil.Tween({y:letfY})
.to({y:orignalY},3000)
.onUpdate((object)=>{
this._cube.worldLocation=new Type.Vector(this._cube.worldLocation.x,object.y,this._cube.worldLocation.z);
});
const toLeftTween=new TweenUtil.Tween({y:orignalY})
.to({y:letfY},3000)
.onUpdate((object)=>{
this._cube.worldLocation=new Type.Vector(this._cube.worldLocation.x,object.y,this._cube.worldLocation.z);
});
const toRightTween=new TweenUtil.Tween({y:orignalY})
.to({y:rightY},3000)
.onUpdate((object)=>{
this._cube.worldLocation=new Type.Vector(this._cube.worldLocation.x,object.y,this._cube.worldLocation.z);
});
//一次方块来回动画耗时(ms)
const takeTime=3000*4;
toLeftTween.chain(leftToOriginalTween.chain(toRightTween.chain(rightToOriginalTween))).start();
setInterval(()=>{
toLeftTween.chain(leftToOriginalTween.chain(toRightTween.chain(rightToOriginalTween))).start();
},takeTime)
}
}
利用tween动画实现运动器的效果,注意这里的chain()函数使用,不能直接一直chain动画,而需要嵌套chain动画。
|