How to change the color of tk2dsprite? In the properties of the script tk2dsprite is the color that can be changed from the editor, and how to change it from another script?

And how can I change color smoothly, within one second after launch?

GetComponent<tk2dsprite>().GetComponent<Color>().a = 255 

It does not work, says that it is not a variable, therefore it cannot change.

    1 answer 1

    For change:

      Color _Color= GetComponent<tk2dsprite>().GetComponent<Color>(); _Color = new Color(0.2F, 0.3F, 0.4F, 0.5F); 

    https://docs.unity3d.com/ScriptReference/Color-ctor.html

    For smoothness: it is necessary to change the values ​​of rgba within a second (depending on the required color).

      void ChangeColor() { // Секунда(или несколько) делить на число - чем больше число тем плавней. float time = 1 / 10; float r = _Color.r + time if (_Color.r < 1) { _Color = new Vector4( r, _Color.g, _Color.b, _Color.a); Invoke("ChangeColor", time); } } 

    Run ChangeColor () in Start if it is a "tk2dsprite" script. Or just call once if it is a different script.

    • Partially works. Color must be assigned in this way color = new Vector4(1, 1, 1, 1); _tk2dsprite.color = color; color = new Vector4(1, 1, 1, 1); _tk2dsprite.color = color; - Dmitrii