Recommended for learning unity scripts: unity3d Official WebsiteIndex
In the previous case, we have built a high-score ranking framework, and then we will further improve some details.
First, use ugui. color to adjust the text color.
On the inpector panel, you can see that the text color in the high score list has changed:
You can also make adjustments in the script:
The adjusted results are as follows:
For more information about gui. Color, see index on the official website.
Gui. color (R, G, B, A); is the construction method of color. RGB color is used, and a represents the Alpha value.
Of course, you can place gui. color in the for loop to highlight the first place:
The running result is:
If you want to display the color at the input, you can use a for loop:
The effect is as follows:
Setting gui. color at the right position will make your game text appear in the desired color.
Of course, we can also add some cool effects to it, such as gradient.
Explanation on the official websiteDocument
WhereInstanceCodeAs follows:
// Converts a white color to a black one trough time. vaR lerpedcolor: color = color. white; function Update () {lerpedcolor = color. lerp (color. white, color. black, time. time );}
Simply put, it is to jump from the first color to the second color.
Operation discoveryText colorBut we want to add a flickering effect to it.
Here we will introduce a new function:Mathf. Pingpong
It is used for random generation.A value not greater than the length and never less than 0.
The returned value will be moved back and forth between 0 and length..
We apply it to the settings of GUI. color:
You will find that your text is in the black and whiteFlashing Effect of Loop.
You can useThis method:
IfIf you think the black is too deep, you can adjust the last parameter value in the lerp function:
In this way, when the color changes from white to gray, it will become white again.