Hello! It’s me again, I’m working on a project which uses Trigger Enter Collision which enables UI prompts, however, I would also like to perform some actions like showing another UI element and playing voice lines when a certain key was pressed, thus, I used Key Up/Down command. If there’s any workaround to make this goal possible I’ll be grateful to learn but I’ll definitely be needing a guide. I would really appreciate any help. Thank you!!
Here’s the UI
and here’s the hierarchy
var LoloTrigger = pc.createScript('loloTrigger');
// initialize code called once per entity
LoloTrigger.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
this.entity.collision.on('triggerleave', this.onTriggerLeave, this);
this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);
this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp, this);
this.app.root.findByName('Reply1').enabled = false;
this.app.root.findByName('Reply2').enabled = false;
this.app.root.findByName('Reply3').enabled = false;
};
// update code called every frame
LoloTrigger.prototype.update = function(dt) {
};
LoloTrigger.prototype.onTriggerEnter = function(result) {
//this.entity.sound.play('PaperBtn');
this.app.root.findByName('Lolo Interactions').enabled = true;
if (this.app.keyboard.isPressed(pc.KEY_Z)) {
this.app.root.findByName('Reply1').enabled = true;
this.app.root.findByName('Reply2').enabled = false;
this.app.root.findByName('Reply3').enabled = false;
}
if (this.app.keyboard.isPressed(pc.KEY_X)) {
this.app.root.findByName('Reply2').enabled = true;
this.app.root.findByName('Reply1').enabled = false;
this.app.root.findByName('Reply3').enabled = false;
}
if (this.app.keyboard.isPressed(pc.KEY_C)) {
this.app.root.findByName('Reply3').enabled = true;
this.app.root.findByName('Reply1').enabled = false;
this.app.root.findByName('Reply2').enabled = false;
}
};
LoloTrigger.prototype.onTriggerLeave= function(result) {
//this.entity.sound.play('PaperBtn');
this.app.root.findByName('Lolo Interactions').enabled = false;
};