Search Unity

[Unity 2D] Requesting Assistance with Pixel Palettes

Discussion in '2D' started by demnish, May 27, 2018.

  1. demnish

    demnish

    Joined:
    Feb 15, 2017
    Posts:
    2
    Hello everyone, this will be my first post on this forum, I've used Unity for a small amount of time and this is the first time I bumped into a problem that I could not solve on my own or find a tutorial about that I could understand.

    What I could need some help with, is how I'm supposed to create a palette system for 20 different colors that can be changed, the change would be between pre-determined colors that I set up for the players to use. (Example: Like changing skin color, but not have free reign to change it to red)

    Here is a picture I set up with colors and the available ones:


    I can create sprites with different colors without a problem, however that feels like a "noob"-way to do it when it should be possible to let the player choose colors with the use of scripts. Not to mention having all those sprites clogging up memory while also being, in the long run, a pain to design when it comes to animations and different characters.

    Anyone got any ideas on how I should approach this?
    Kind regards, Demnish.
     
  2. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    I know of 2 ways to do what I think you are after.

    1. You programmatically create the color variations (getpixel / setpixel)
    2. You use a shader that swaps the colors “on the fly”

    If you search the forums, you will for sure find details / sample code for both approaches
     
    demnish likes this.
  3. demnish

    demnish

    Joined:
    Feb 15, 2017
    Posts:
    2
    Thank you for your reply :)