Hi,
I have become stuck with a function I want to make.
I have 3 entities each containing multiple lights.
I used the model swap tutorial to work well with swapping out objects, but wanted to extend that to hide and show entities. I want to show an initial entity (a) then show others on key presses as shown below but I’m a little stuck how to do this?
var Updatelights = pc.createScript('updatelights');
Updatelights.attributes.add('a', {
type: 'entity',
assetType: 'entity'
});
Updatelights.attributes.add('b', {
type: 'entity',
assetType: 'entity'
});
Updatelights.attributes.add('c', {
type: 'entity',
assetType: 'entity'
});
Updatelights.prototype.initialize = function() {
this.app.keyboard.preventDefault = true;
};
// update code called every frame
Updatelights.prototype.update = function(dt) {
var app = this.app;
if (app.keyboard.isPressed(pc.KEY_Z)) {
if (this.entity.entity.entity !== this.b.resource) {
// update the model component to the new model
this.entity.entity.entity = this.b.resource;
}
} else {
if (this.entity.entity.entity !== this.a.resource) {
// restore original model
this.entity.entity.entity = this.a.resource;
}
if (app.keyboard.isPressed(pc.KEY_X)) {
if (this.entity.entity.entity !== this.c.resource) {
// update the model component to the new model
this.entity.entity.entity = this.c.resource;
}
} else {
if (this.entity.entity.entity !== this.a.resource) {
// restore original model
this.entity.entity.entity = this.a.resource;
}
}
}
// clear
if (app.keyboard.isPressed(pc.KEY_C)) {
app.assets.load(this.c);
}
};