Hi There,
I was trying to check if the controls are attached to the current camera, to be able to toggle controls on or off.
export const CanvasControlToggleBtn = function (scene:Scene) {
var advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI("UI");
var button1 = Button.CreateSimpleButton("but1", "ON");
button1.width = "150px"
button1.height = "40px";
button1.color = "white";
button1.cornerRadius = 20;
button1.background = "green";
var attached = scene.attached;
button1.onPointerUpObservable.add(function () {
var camActive = scene.activeCamera
if (attached) {
console.log('detach');
button1.textBlock.text = "ON";
camActive.attachControl(canvas);
}
else {
console.log('attach');
button1.textBlock.text = "OFF";
camActive.detachControl();
// Error camera will be reattached after each mouseUP again
}
});
advancedTexture.addControl(button1);
}
I’m using this snippet.
Which I got somewhere online, can’t remember, but the
var attached = scene.attached;
Returns undefined.
What’s the correct way to check if the controls are attached to a specific camera?
Thanks!