- Home /
Question by
Noxury · Mar 09, 2017 at 04:08 PM ·
uicolor changenewtween
How to fade color of new UI-components with iTween
Hi, I want to make an ui image to fade in using iTween.
it seems that the new UI (since 4.6) components' color properties are not supported? What am I doing wrong in this code snippet?
iTween.ValueTo(icon.gameObject, iTween.Hash("from", new Color(1f,1f,1f,0f), "to", new Color(1f,1f,1f,1f), "time", 2f, "onupdate", "OnColorUpdated"));
I even downloaded the updated version of iTween.
Comment
Best Answer
Answer by AdbC99 · Jul 25, 2018 at 05:06 AM
Bit of a late answer @Noxury but here is how I am doing it:
[Tooltip("Reference to a UI image for fading in")][SerializeField]
private UnityEngine.UI.Image FadeImage;
[Tooltip("Length of the fade")][SerializeField]
private float FadeTimer = 2f;
[Tooltip("Delay until fades beghins")][SerializeField]
private float FadeInDelay = 1f;
[Tooltip("Color to fade to")][SerializeField]
private Color EndColor = Color.white;
[Tooltip("Color to fade from")][SerializeField]
private Color StartColor = Color.clear;
public void updateColor(float val)
{
FadeImage.color = ((1f-val) * StartColor) + (val * EndColor);
}
private void Fade()
{
// Commented out unity cross fade since this seems to
// have bugs when working on transparent images
// FadeImage.CrossFadeColor(FadeColor, FadeTimer, false, true);
iTween.ValueTo(this.gameObject,iTween.Hash("from",0f,"to",3f,"delay",FadeInDelay,"time",FadeTimer,"onupdate","updateColor"));
}