I’m not having issues with the second code sample you provided on a test sprite. Since you said it works when decreasing, it could be an issue with the logic that changes ‘myAlpha’. You can add a Debug.Log(myAlpha.ToString()); to check to make sure it’s actually changing the way you intended.
As for why the first code worked in older versions, it’s because Unity had a few shortcut variables (such as ‘renderer’), that did a behind the scene GetComponent. However GetComponent is actually a relatively expensive operation, so they removed them in hopes that users would instead cache the component reference.
Here’s the full code I used for testing. I created a new sprite object in a scene and applied a random sprite to it.
hi @OncaLupe
your code is working fine
but when a sprite in the scene have alpha=1 ,
but if you decrease the alpha Chanel in the editor to something like 50 from 255 ,
the top value of alpha chanel change to that.
and even with your code , you can’t set alpha to 1 (or 255) actually.
i use Unity 5.2.0f3 (32-bit)
thanks.