Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Change a Color in a Sprite progromatically?

Discussion in '2D' started by outtoplay, Jul 1, 2014.

  1. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    I'm hoping for efficiency there is a way to do this...

    I have a dozen or so 2D characters. I can explode them into sprite 'chunks.' Each character is a different color, I have 1-12 chunks that are the same for each character except for being the color of the character. Instead of duplicating the dozen chunks a dozen times, I was under the impression that I could change the sprite color via script depending which character got killed. I.E. Red character killed, gimme red chunks... not change the entire color (via 'Tint0), just the one color, say, orange or yellow or red.'

    Does anyone have a thought? I'd appreciate it. below is a sample of chunks.
    BlockFishChunks.png
     
  2. Dogg

    Dogg

    Joined:
    Mar 5, 2014
    Posts:
    203
    I think your best bet is to duplicate the dozen chunks. I do not think there is another way to change the color(though I could be wrong I'm not a expert Unity user).
     
  3. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Yeah... I was sure there was a way and it would be way cool, but like's too short, so I'll pack them into a spritesheet and be done with it.
    Thanks Dogg,
    B-
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
    other options/ideas,
    - custom shaders to adjust color properly (asset store had some sprite palette recolor(?) shader also)
    - build the chunks from multiple sprites (that way you can use that tint color for the orange part only, which would be white image initially)
    - building different other color sprites at start with script, from one set.. with SetPixel()
     
  5. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Thanks, MGear,

    I'll investigate SetPixel() more next week. The chunks are for an update to my 2d Fish Assets, Silly Swimmers so a coded color change would make sense. They already have skeletons, but who doesn't like chunks OnDeath(); :cool:

    I'll push out the spritesheet solution now and likely try the other solution in a future update. Thanks again.

    B-