[LayaAirIDE3]场景中运行时脚本 无法继承自Laya.Script只能自己创建调用帧循环吗?

 
//目前能实现的仅是这样实现帧循环
 
const { regClass } = Laya;
import { 测试Base } from "./测试.generated"; 
@regClass()
export class 测试 extends 测试Base { 
  onAwake(): void {
       
        Laya.stage.frameLoop(1, this, this.onUpdate);
    } 
    onUpdate(): void {
        console.log("dddd");
       
    } 
    onDestroy(): void {
       
        Laya.stage.clearTimer(this, this.onUpdate);
    }
}
 

LayaAir大为

赞同来自:

Runtime脚本是没有onUpdate方法的,如果要用onUpdate方法,可以参考下面这段代码,在一个组件脚本中获取Runtime对象,然后在组件脚本中调用onUpdate
 
import { RuntimeScript } from "./RuntimeScript";

const { regClass, property } = Laya;

@regClass()
export class NewScript extends Laya.Script {

    private ui : RuntimeScript;
    onStart() {

        // 获得场景的Runtime对象
        this.ui = this.owner.scene as RuntimeScript;

        // Button添加鼠标事件,让Image不显示
        this.ui.Button.on( Laya.Event.MOUSE_DOWN, null, ()=>{
            this.ui.Image.visible = false;
        });
    }
}

要回复问题请先

商务合作
商务合作