Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by EstragonHelmer · Feb 08, 2018 at 09:20 PM · material color

sharedMaterial.SetColor colours the entire bounding box, rather than tinting the sprite

I want to be able to easily swap the colour scheme on my game using code, rather than having a bunch of different versions of each sprite. All I want to do is tint my sprites, using their material.

When I change the 'Tint' of the material using the inspector, it works fine, tinting the sprites. But when I try to change it in code, it just colours the whole bounding box of the sprite 1 solid colour.

I'm new to using C#, so it may well be just me making a dumb mistake.

I think the issue might be the "_Color" in the SetColor code. I've seen in other posts, that it should be "_TintColor", but when I use that Unity just tells me the material doesn't have a _TintColor.

 sprite.sharedMaterial.SetColor ("_Color", newColour);

Here's my whole script, in case I've made some other stupid error in it that causes this.

     public ColourSchemes parent;
     private string currentColours;
     private Color newColour;
     private Renderer sprite;
 
     void Start ()
     {
         sprite = gameObject.GetComponent<Renderer> ();
         currentColours = "Unset";
     }
 
     void Update ()
     {
         //check for colour scheme change
         if (currentColours != parent.currentColours)
         {
             if (parent.currentColours == "Default")
                 DefaultColours ();
             if (parent.currentColours == "Midnight")
                 MidnightColours ();
             
             //set colour
             sprite.sharedMaterial.SetColor ("_Color", newColour);
         }
     }
 
     void DefaultColours ()
     {
         newColour = new Color (0xFF, 0xFF, 0xFF, 0xFF);
         currentColours = "Default";
     }
 
     void MidnightColours ()
     {
         newColour = new Color (0xFF, 0x00, 0x00, 0xFF);
         currentColours = "Midnight";
     }

'parent' is the script that handles which colour scheme is active, this script just sets one of the colours.

'currentColours' is to hold what colour scheme is active in THIS script. I use it to compare to the parent script.

'newColour is purely for clarity of reading the script. I know I could set that directly in the 'SetColor' code, but this makes it easier for me to edit at a later date.

'sprite' is my renderer, and as my colours ARE changing, just not the way I want, I guess this is working correctly.

Comment
Add comment
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
0

Answer by EstragonHelmer · Feb 08, 2018 at 11:42 PM

UPDATE!

Playing around with different things, I found that using the standard Unity 0 to 1 scale for setting the colour, it tints correctly instead of colouring the whole bounding box.

Is there a way to convert my hex code to that?

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

123 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 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 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 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 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 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 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

How can i stop the stretch effect of a material when i add it to an object and then resize it 2 Answers

Why is my plane not changing colors? 1 Answer

Changing a material's colors anywhere else besides the Update function has no effect,Changing Material's color works on Update but not on another method 0 Answers

Fading texture to black is not working correctly 1 Answer

Change the color of material based on percentage of health remaining 1 Answer


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