Y
Y
Yugg02020-02-03 23:49:40
Unity
Yugg0, 2020-02-03 23:49:40

How to change the color of a button, panel, text, through a script?

For the project, you need to make it possible to change the color of the panel, button, text through the script.
Since I have not used UI elements before, I do not know how to implement this?
I read the Unity documentation - I did not see anything I needed.

Who knows, tell me, I will remember this for the rest of my life, and I will not ask more easy questions of this type.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-02-04
@GavriKos

Each component has its own parameter for this.
In Unity, the button and panel have no color - they use Image.
The Image component has a color parameter - change it to health.
The text is a little more complicated - there are several types of them (TMPro, Unity), but they all also have a color parameter. In
total, you need your script to know about the necessary components (SerializeField, GetComponent, etc. - basic things) and change their parameter to health.
Well, learn to use Google - the answer is in any UI tutorial,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question