[SOLVED] How would I change the opacity of a button using another button?

So I’d like to change Opacity value of a button using another button. Basically I want a specific button to show up after I press a button. Default opacity of the button is 0 and I want to make it 100% after I press a button. Do I need to use a specific attiribute or type: ‘rgba’ should work?

Hi @sugarr!

If you use a button component there are three properties to change the color. I think to change the inactiveTint properity, you can do something like below. Don’t forget to assign the image entity of the button component.

Opacity of 0:

this.entity.button.inactiveTint = new pc.Color(1, 1, 1, 0);

Opacity of 255:

this.entity.button.inactiveTint = new pc.Color(1, 1, 1, 1);

Please let me know if it works as I haven’t tested it.

By the way, it looks like you need to change the opacity of the element component if you want to change the default opacity. So that has nothing to do with the button component as I thought before. It also seems like the result will be about the same as just disabling and enabling the entity?

1 Like

This is how I would do it https://playcanvas.com/project/1196641/overview/opacity-on-click

But it sounds like what you really want to do is in this topic: How to hide/activate an element using different script

2 Likes