• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Maverrr · Jul 14, 2013 at 01:50 AM · texturematerialcolor

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.

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Benproductions1 · Jul 14, 2013 at 01:57 AM

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: http://answers.unity3d.com/questions/209573/how-to-change-material-color-of-an-object.html

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 :)

Hope this helps,
Benproductions1

Comment
creighcl
crodriguez
OR_Parga

People who like this

3 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Maverrr · Jul 15, 2013 at 01:33 AM 0
Share

thanks for the quick reply I had a look at the "tint color", however I don't think this is entirely what I want, as I want to be able to edit all the three colors not just the texture as a whole. (or am I doing something wrong, I read something about 50% gray works the best from the link: http://answers.unity3d.com/questions/209573/how-to-change-material-color-of-an-object.html does this have to do anything with it?)

Could you help explain a bit more in regards to Texture2D, I've read into it before and tried but just couldn't seem to get it to work. My understanding: I have to declare the texture public texture2D testTexture; the texture needs to be readable in the import settings then within my button code which is on my GUI, I'll have to place: GetPixels, which will return an array, then find which pixels are the right color, then change them, to the color it says on the button or do I straight out use SetPixels?

avatar image Benproductions1 · Jul 15, 2013 at 01:45 AM 0
Share

@Maverre that is exactly what you have to do.
If you wanted to, you could do it using shaders, which would be faster, but you'd have to learn how to write them yourself :)

avatar image Maverrr · Jul 16, 2013 at 02:21 AM 0
Share

Thanks Benproductions1 I'll have a look into shaders and see where that leads me, otherwise I'll give the other way another crack and hopefully I can get it to work.

avatar image OR_Parga · Nov 09, 2015 at 12:59 AM 0
Share

Don't forget call the Texture2D.Apply() method for the changes to take effect.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing two different objects renderer colour 1 Answer

Material doesn't have a color property '_Color' 4 Answers

I'm trying to change a material, texture or color and it doesnt work 0 Answers

How to access Emission Color of a Material in Script? 5 Answers

Changing Eye Colour (Colour only non-white parts of a texture?) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges