- Home /
Sprite smooth fade out/in
Hi, So I wrote a little code for my sign to "Smoothly fade out/in".
Sprite appears and disappears as intended however it doesn't fade smoothly.
void Start () {
myTrigger = GetComponent<Collider2D>();
booble = whichSpriteToFade.GetComponent<SpriteRenderer> ();
}
void Update(){
isTouchingSign = Physics2D.IsTouchingLayers (myTrigger, whoIsPlayer);
if (isTouchingSign) {
Debug.Log ("Is touching sign it's fading in");
fade = Mathf.SmoothDamp (0f, 100f, ref fadespeed, fadeTime);
booble.color = new Color (1f, 1f, 1f, fade);
} else {
Debug.Log ("Is not touching sign it's fading out");
fade = Mathf.SmoothDamp (100f, 0f, ref fadeoutspeed, -fadeTime);
booble.color = new Color (1f, 1f, 1f, fade);
}
}
}
Answer by MacDx · Sep 29, 2017 at 09:14 PM
The problem is that, just like RGB values, the alpha value goes from 0 to 1. However, you are trying to make it go from 0 to a 100 so you will never actually see the fading , since the only values that matter go from 0 to 1 but you are basically skipping that. So replace the 100f with a 1f inside your SmoothDamp functions.
@VIPU$$anonymous$$S
I did that however sprite only gets the first value which is 0.16 a and stops there.
Well, that's probably because nowhere in your code are you adding/substracting to/from your fadeTime variable. If you never change that value the SmoothDamp function will always return the same value.
Answer by VIPUKS · Sep 30, 2017 at 09:24 AM
I did that however sprite only gets the first value which is 0.16 a and stops there.
Your answer
![](https://koobas.hobune.stream/wayback/20220612135930im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fade out sprite on click 4 Answers
Fade In / Out UI Image 3 Answers
Changing a GUITexture's alpha gives me no effect in game. 0 Answers
Fade logo before main menu 2 Answers
Fade in with CrossFadeAlpha 1 Answer