003.射线检测

2019-11-25  本文已影响0人  cmd_ts
export default class ray_test extends Laya.Script {
    /** @prop {name:intType, tips:"整数类型示例", type:Int, default:1000}*/
    public intType: number = 1000;
    /** @prop {name:numType, tips:"数字类型示例", type:Number, default:1000}*/
    public numType: number = 1000;
    /** @prop {name:strType, tips:"字符串类型示例", type:String, default:"hello laya"}*/
    public strType: string = "hello laya";
    /** @prop {name:boolType, tips:"布尔类型示例", type:Bool, default:true}*/
    public boolType: boolean = true;
    // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    
     /** @prop {name:btn, tips:"按键位置", type:Node, default:1000}*/
     public btn:Laya.Node = null;
    private hitResults:Array<Laya.HitResult> = new Array<Laya.HitResult>();

    constructor() { super(); }

    onAwake(){
        this.btn.on(Laya.Event.CLICK,this,this.btn_test);//为按钮绑定单击事件

        Laya.Scene3D.load("res/3dres/LayaScene_ccc/Conventional/ccc.ls",Laya.Handler.create(this,this.scene_loaded));
    }
    
    scene_loaded(scene:Laya.Scene3D){
        Laya.stage.addChild(scene);
        scene.zOrder = -1;

        var from:Laya.Vector3 = new Laya.Vector3(0, 0, 0);
        var to:Laya.Vector3 = new Laya.Vector3(0, 0, 3);
        var lineSprite:Laya.PixelLineSprite3D = scene.addChild(new Laya.PixelLineSprite3D(1)) as Laya.PixelLineSprite3D;
        lineSprite.addLine(from, to, Laya.Color.RED, Laya.Color.RED);

        scene.physicsSimulation.raycastAllFromTo(from, to, this.hitResults);
        
    }

    btn_test(){
        if (this.hitResults.length > 0) {
           console.log('> 0');
        }
        else
        {
            console.log('0'); 
        }
    }

    // hitResults(){

    // }
    
    onEnable(): void {
    }

    onDisable(): void {
    }
}
上一篇下一篇

猜你喜欢

热点阅读