[SOLVED] Disabling entity for specific time when Button clicked

When a certain button is clicked I am able to disable an entity but I do not know how to specify how long it should be disabled for.

Editor - https://playcanvas.com/editor/scene/896589
Code Editor - https://playcanvas.com/editor/code/674640?tabs=29638492,29641962

The code is under the AMajor.js and the button that has to disappear is ‘ELow’.
To test it launch the guitar scene and click on the Major Chord Button. Under that you will see “A”. Once that is pressed the top right button “E” should be disabled until the sound finishes playing and then “E” should be enabled again.
Thank you

Hi @Krish_USCan,

There isn’t any Playcanvas specific method to specify how long an entity should remained disabled.

You can do this using a native Javascript method, setTimeout:

// the following call will enable this entity after 3sec have passed
window.setTimeout( function(){
   this.entity.enabled = true;
}.bind(this), 3000); 

This is the quick way to achieve it. A more proper solution would be to keep track of time passed in your script update method, and after 3sec do the same.

1 Like

Thank you it works now

1 Like

does .bind(this), 3000); work for scripts not accosiated with this (sorry for my terrible english)