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 Hydropulse17 · Apr 06, 2016 at 10:40 PM · shadermaterialcoloradditivetint

Changing alpha channel of the tint color on a material

I see the same question all over but they're all talking about sky boxes and shaders.

I have a shield bubble around my ship, and I want it to disappear visually, and reappear when something hits it. I wrote this script here.

 public Color myColor;

 void Update () {

     if (myColor.a > 0)
     {
         myColor.a -= 0.1f;
     }

     GetComponent<Renderer>().material.color = myColor;

 }

 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Asteroid")
     {
         myColor.a += 150;
     }
 }

On runtime, it tells me that the material has no color property. The material is using the particles/additive shader, which has the tint color property. How would I access that property?

When I try the script on the standard shader, it doesn't even work they way I think it should. When an asteroid hits it, it puts it at 255 alpha instead of 150, and it doesn't deplete unless I open the color picker tool, which forces it to update I guess. I tried making the color variable private.

Comment
Add comment · Show 2
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 Hydropulse17 · Apr 07, 2016 at 01:27 AM 0
Share

I still don't know how to access tint color, but in case someone else stumbles upon this question looking for answers, I did solve the latter half of my problem.

It seems like when I access myColor.a, it isn't on an intuitive scale of 0-255, but ins$$anonymous$$d 0.0f - 1.0f.

avatar image toddisarockstar · Apr 08, 2016 at 04:47 AM 0
Share

also keep in $$anonymous$$d that when you change alpha by script that it is a float from 0 to 1. also remember that you need to have a transparent shader on the object for this to work!

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by saschandroid · Apr 07, 2016 at 07:48 AM

Have you tried to manipulate the tint color of the shader directly?

 GetComponent<Renderer>().material.SetColor("_TintColor", myColor);

PS: If you have selected your material, you can click on the little gear icon in the inspector and then on Edit Shader. Now you can see which properties the shader has and what their string representation is to access them.

Comment
Add comment · Show 3 · 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 Hydropulse17 · Apr 08, 2016 at 03:48 AM 0
Share

YES, THAN$$anonymous$$YOU. That's exactly what I was asking for, I didn't know how to do that. And it's a good thing to know about the shader strings. I was settling for a standard transparent shader ins$$anonymous$$d of the additive, but now I don't have to. Thanks again.

avatar image saschandroid Hydropulse17 · Apr 08, 2016 at 05:59 AM 0
Share

I have converted my comment to an answer, please mark it as the correct one.

avatar image Hydropulse17 · Apr 10, 2016 at 08:40 AM 0
Share

I wish I could do that, as the thread op. This isn't the first time I've been answered in comment form.

avatar image
0

Answer by JigneshKoradiya · Apr 07, 2016 at 05:42 AM

public Color myColor;

void Update () {

  if (myColor.a > 0)
  {
      myColor.a -= 0.001f;
  }
  GetComponent<Renderer>().material.color = myColor;

} void OnTriggerEnter(Collider other) {

  if (other.gameObject.tag == "Asteroid")
  {
      myColor.a += 1;
  }


}

// use this script and please check if material of your object must have color property

Comment
Add comment · Show 2 · 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 Hydropulse17 · Apr 08, 2016 at 03:52 AM 0
Share

I had tried messing with the values, and I figured that part out. I was asking how to access the tint color property on a shader that didn't have a regular color property. saschandroid gave me what I was looking for. GetComponent().material.SetColor("_TintColor", myColor);

avatar image JigneshKoradiya Hydropulse17 · Apr 08, 2016 at 05:20 AM 0
Share

paste your shader code here if u are using any shader or give your shader name if u are using unity shader

avatar image
0

Answer by jhuynh_isobar · Sep 02, 2016 at 07:48 PM

I'm using Unity's: Particles/Additive shader, and I tried this code, but i keep getting an error: Material doesn't have a color property 'Color' UnityEngine.Material:get_color() FadeCylinder:MaxAlpha() (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:47) c_Iterator1C:MoveNext() (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:81) UnityEngine.MonoBehaviour:StartCoroutine(String, Object) FadeCylinder:FadeIn(Single) (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:136) FadeCylinder:FadeIn() (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:125) FadeCylinder:Update() (at Assets/Wyndham/Sandbox/CocktailTransition/Script/FadeCylinder.cs:153)

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

63 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

Related Questions

Using Texture as HDR color? 2 Answers

Tint Multiple Textures Separately 1 Answer

Modifying shader requires restarting application 0 Answers

Tree Creator textures seem missing 1 Answer

Tint a UI sprite with a gradient 0 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