Sun_and_Moon_Digital
7 months agoMember
Door (portal) Visibility
I want a door (Worlds portal) to appear when a player enters a trigger. It's set to invisible by default. Script1 makes the door visible on enter and hides it on exit, but the info panel (a child of the door) stays visible. I’d like the info panel to follow the door’s visibility automatically. Script2 treats the door and info panel as seperate objects and doesn't work. thx
script1
import { Entity } from 'horizon/core';
import * as hz from 'horizon/core';
class ToggleDoorVisibility extends hz.Component<typeof ToggleDoorVisibility> {
static propsDefinition = {
door: { type: hz.PropTypes.Entity },
};
start() {
const doorEntity = this.props.door!;
if (!doorEntity) return;
// When a player enters the trigger, make the door visible
this.connectCodeBlockEvent(this.entity, hz.CodeBlockEvents.OnPlayerEnterTrigger, () => {
doorEntity.visible.set(true);
});
// When a player exits the trigger, make the door invisible
this.connectCodeBlockEvent(this.entity, hz.CodeBlockEvents.OnPlayerExitTrigger, () => {
doorEntity.visible.set(false);
});
}
}
hz.Component.register(ToggleDoorVisibility);
script2
import { Entity } from 'horizon/core';
import * as hz from 'horizon/core';
class ToggleDoorAndInfoPanelVisibility extends hz.Component<typeof ToggleDoorAndInfoPanelVisibility> {
static propsDefinition = {
door: { type: hz.PropTypes.Entity },
infoPanel: { type: hz.PropTypes.Entity },
};
start() {
const doorEntity = this.props.door!;
const infoPanelEntity = this.props.infoPanel!;
if (!doorEntity || !infoPanelEntity) return;
// When a player enters the trigger, make the door and info panel visible
this.connectCodeBlockEvent(this.entity, hz.CodeBlockEvents.OnPlayerEnterTrigger, () => {
doorEntity.visible.set(true);
infoPanelEntity.visible.set(true);
});
// When a player exits the trigger, make the door and info panel invisible
this.connectCodeBlockEvent(this.entity, hz.CodeBlockEvents.OnPlayerExitTrigger, () => {
doorEntity.visible.set(false);
infoPanelEntity.visible.set(false);
});
}
}
hz.Component.register(ToggleDoorAndInfoPanelVisibility);