Need a way for a button to flash red

Looking for a quick dirty way to subscribe a button to a red flash if answer (button) is wrong.

Currently just checking if the current button pres is right by checking an index in my array, if it’s right then I play a sound and if it’s wrong just play the wrong sound:

                button1.onPointerUpObservable.add(function() {
                if(button1.textBlock.text == String(arr[currentKey])){
                    numbers.text = numbers.text + String(arr[currentKey]);
                    currentKey += 1;
                    GameSystem.soundSystem.keytone.play();
                }
                else{
                    GameSystem.soundSystem.Wrong_Answer.play();
                }
            });

You could try to play with the color property over time for instance ? https://www.babylonjs-playground.com/#XCPP9Y#1931

2 Likes

You could also use the Babylon animation system to create a timed animation, though we don’t have a way to animate hex values, so you do need to have a container to hold the animated color3. In this case I created a standard material to hold the color and then pulled that color into the button as a hex:

https://playground.babylonjs.com/#FFVJW9

2 Likes

Thanks guys!

1 Like