How to change a certain colour in a texture?

At the moment I have one texture on a sphere and the texture has three different colours:

   eg: white or in RGBA (1,1,1,1), Black (0,0,0,1) and red(1,0,0,1).

I then have three different buttons one for each colour and I want that button to change the texture colour to green (0,1,0,1). My initial plan of attack was to do something like this: Texture.color(1,1,1,1) = color(0,1,0,1). Selecting all the white from a texture and make it green. I’ve tried to use getColor & setColor, while using a material that is the texture.
I’m quite lost in what to do/ wondering if it is even possible to do in unity. Would I be changing the texture or material/ which would be better?
My Coding experience is quite low, but I’m willing to learn to get it working.

In the end I’ll actually have it so I can change it to any colour using a colour picker, but for testing purposes I just want to stick with one colour.

Any help on this will be much appreciated.

Hello,

If the only thing that has to change on you’r texture is the “tint color”, then changing the color of the material is just fine. It’s also a lot faster, since you’re just telling the GPU to use a different color for tinting, rather than a completely different texture.
On how to do this, check here: How to change material color of an Object - Unity Answers

If you want to change the texture itself (not very easy), you will have to:
Firstly, cast it to a Texture2D. This is Unity’s “editable” texture. However note, that by default you cannot grab the Texture from an object and cast it to a Texture2D, unless you change some import settings.
This Texture2D allows you to do things like GetPixel and SetPixel, allowing for more accurate, pixel based color “setting” and “getting”.
Check the documentation on Texture2D for more information :slight_smile:

Hope this helps,
Benproductions1