I need to change a plane ‘materials’ property from the script. At the moment I am doing it in a very complex way - by creating several planes positioned exactly at the same location and having different texture each. Then I trigger ‘visible’ property of each plane through the scenes (I have a separate scene created for each case). The relevant part of the code is below. It works but it is unnecessarily complex and expanding this to several areas that I need to ‘trigger’ will increase the complexity of the code and resources required. It would be much easier if I could change the texture (basically link another .png image already existing in the media library) from the script.
var LookingIn = 0;
var myFunction = function() {
// if Kitchen 99 is shown switch to LivingRoom and reset
if (LookingIn == 3) {
symbol.controllers.display.elements.ShowLivingRoom.activate();
// LookingIn = 0;
Z.everyOff(myFunction);
}
// if Kitchen66% is shown switch to Kitchen99
if (LookingIn == 2 ) {
symbol.controllers.display.elements.ShowKitchen99.activate();
LookingIn = 3;
}
// if Kitchen33% is shown switch to Kitchen 66
if (LookingIn == 1) {
// Switch to Kitchen66 and increase LookingIn
symbol.controllers.display.elements.ShowKitchen66.activate();
LookingIn = 2;
}
}
parent.on(“intersectionenter”, (e) => {
// Runs when intersectionenter occurs on the parent node
// The argument e contains useful info about this event:
// https://docs.zap.works/studio/scripting/reference/object/events/intersectionenter/
// Show Kitchen 33%
symbol.controllers.display.elements.ShowKitchen33.activate();
// Activate every 1000ms myFunction
LookingIn = 1;
Z.every(1000,myFunction);
});
parent.on(“intersectionleave”, () => {
// Runs when intersectionleave occurs on the parent node
// https://docs.zap.works/studio/scripting/reference/object/events/intersectionleave/
// differentiate if intersection is left after living room is shown or not
// Reset all when intersection was left and return back to Kitchen00
if (LookingIn != 3) {
symbol.controllers.display.elements.ShowKitchen.activate();
Z.everyOff(myFunction);
}
LookingIn = 0;
});