LeanTween.alpha with 2D sprites doesn't work.

Hello,

I’m using the LeanTween library.

But unfortunatly the alpha method doens’t work.
I want a fadein and a fadeout effect but I can’t use this method on 2D sprite.

Any tips?

Thanks.

You can use use the value method, which lets you tween any value. So a very simplified version of this (attached to the sprite you want to fade would look something like this:

	SpriteRenderer my_sprite;

	void Awake()
	{
		my_sprite = GetComponent<SpriteRenderer>() as SpriteRenderer;
	}
	
	public void FadeIn()
	{
		LeanTween.value( gameObject, setSpriteAlpha, 0f, 1f, 1f );
	}
	
	public void FadeOut()
	{
		LeanTween.value( gameObject, setSpriteAlpha, 1f, 0f, 1f );
	}
	
	public void setSpriteAlpha( float val )
	{
		my_sprite.color = new Color(1f,1f,1f,val);
	}
1 Like

I just wanted to update everyone, that the latest version on Github has fixed this issue. You can now tween a 2d sprite. This feature will eventually get pushed to the Asset Store as well, I will be pushing an updated version probably this week.

Cheers,
Russ

1 Like

Very cool.