Home>
In Unity, how do we make the fading effect of the ui object glow fade out?
Let's say we have a picture of an elf with a moon halo
We can add a canvasgroup component to it
we can find out,The alpha value on the component can control the transparency of the picture,From 0 to 1
Then we can achieve the glowing halo effect by controlling the change of the alpha value loop in the code
Here is the code:
using system.collections;
using system.collections.generic;
using unityengine;
public class moonflash:monobehaviour {
private canvasgroup mooncanvasgroup;
private float flashspeed=0.2f;//Halo flash speed
private bool ison=true;
private float maxalpha=0.6f;//The highest alpha value displayed
private float minalpha=0.05f;//The lowest alpha value displayed
void start () {
mooncanvasgroup=getcomponent<canvasgroup>();
}
void update () {
if (mooncanvasgroup.alpha<maxalpha&&ison)
{
mooncanvasgroup.alpha +=flashspeed * time.deltatime;
}
else {
ison=false;
mooncanvasgroup.alpha-= flashspeed * time.deltatime;
if (mooncanvasgroup.alpha<minalpha) {
ison=true;
}
}
}
}
Then mount the script on the picture,The moon glow effect is complete.
Trends
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs