- Home /
Question by
drodrii · Aug 27, 2014 at 05:57 PM ·
gameobjectspriteanimator
SpritesSheet 2D - Changing Color using RBG setting?
Hello everyone, hope everything's good.
So, quick one.
Is it possible to modify the color of an object which is animated by a spritesheet through code? The object is using a 2d Sprite renderer and Animator.
If possible, what/where component should I be looking at?
Thanks for your time.
Comment
Answer by MrMika · Aug 27, 2014 at 08:17 PM
You can either animate the color from one color to the other (using RGBA values) using the animation and animator system or you can use this code that changes the color of the renderer:
gameObject.renderer.material.color = new Color(r, g, b, a);
Where r, g, b and a equals to the red, green, blue and alpha values, in that order. But watch out, this line of code breaks batching so it will increase draw calls (but it shouldn't be a big problem).