Hello Guest

Author Topic: tk2dSprite.color = question  (Read 3843 times)

Lavaflyer

  • Newbie
  • *
  • Posts: 9
    • View Profile
tk2dSprite.color = question
« on: February 04, 2014, 11:44:07 pm »
How do you set the color of an sprite based on its existing color?

oObject.GetComponent<tk2dSprite>().color += new Color (0,0,60);
that doesnt seem to work but for some reason this does work:

oObject.GetComponent<tk2dSprite>().color = new Color (0,0,60);
but that just turns the sprite blue and I want to simply "mask"/overlay it in a light blue.  I have this same problem with text meshes and changing the alpha of a color.  Any help is greatly appreciated, thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite.color = question
« Reply #1 on: February 05, 2014, 10:18:32 am »
You can't mask or overlay a sprite like that. You will have to modify the shader to do it.
Also, colour is a property - you can't add to it but something like this will work:
oObject.GetComponent<tk2dSprite>().color = oObject.GetComponent<tk2dSprite>().color + new Color32(0,0,60,255);

Also, the range of rgb components in Color is 0..1, not 0..255. If you want 0..255 range, use Color32.