In 3.7.0 TweenAlpha was changed so it also works with renderers.
However, the SpriteRenderer component has a color variable which can be used instead of changing the color in the material.
The changes:
- Added a SpriteRender variable after mMat called sRend.
- Added the following in the Cache() method:
if (mRect == null)
{
sRend = GetComponent<SpriteRenderer>();
if(sRend == null)
{
// get material
- Updated the value property to include checks for sRend:
get
{
if (!mCached) Cache();
if (mRect != null) return mRect.alpha;
if (sRend != null) return sRend.color.a; // <------
return mMat.color.a;
}
set
{
if (!mCached) Cache();
if (mRect != null)
{
mRect.alpha = value;
}
else if(sRend != null) // <------
{
Color c = sRend.color;
c.a = value;
sRend.color = c;
}
else
{
Color c = mMat.color;
c.a = value;
mMat.color = c;
}
}