Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Makiavel · Jul 21, 2012 at 12:31 AM · colorlerpalphafade

How to change the alpha element of particles/additive color?

How to change the alpha element of tree leafs color? (Particles/Additive) I try to make them fade in/fade out via lerp. using script, but i can not even find how to target the leaf color in the script. I try something like: renderer.material.color.a = Mathf.Lerp(1.0, 0.0, Time.time); But the material only has a Tint Color, and I don't know how to change that...

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
3
Best Answer

Answer by ScroodgeM · Jul 21, 2012 at 09:04 PM

Color c = renderer.material.GetColor("_TintColor");
c.a = Mathf.Lerp(1.0, 0.0, Time.time);
renderer.material.SetColor("_TintColor", c);

be aware that after 1 second of playing you'll not see any changing

Comment
Add comment · Show 5 · 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 Makiavel · Jul 23, 2012 at 11:55 AM 0
Share

Thank you! This works perfect and is easy to change to suit different tasks. But it only works with materials with only one Element. can I target only one element of the material? Or do I have to have two separate objects, tree and it's leafs?

avatar image ScroodgeM · Jul 23, 2012 at 12:48 PM 0
Share

this works with one instance of $$anonymous$$aterial. so if more then one element uses this $$anonymous$$aterial, this will change color on all of them. if you want to change color only for one material, you should create new instance of $$anonymous$$aterial. example line:

renderer.material = new $$anonymous$$aterial(renderer.material);
- this creates new material and sets it to object. now you can change material - this will not affect to other objects.
avatar image Makiavel · Jul 23, 2012 at 01:21 PM 0
Share

Thanks for the answer, but i meant this: I have an object with mesh renderer that has a material with "size" 2. First one is bumped diffuse, second is particles/additive. Is there a way to target the alpha channel of one of them, the second one in this instance? Because script automatically targets Element 0, wich doesn't have a tint color. It is probably a stupid question, but I can not find the answer in any lesson.

avatar image ScroodgeM · Jul 23, 2012 at 01:24 PM 0
Share

ok i understand

ins$$anonymous$$d of

renderer.material
use
renderer.materials[X]
where X is zero-based index of material, so for second material X=1
avatar image Makiavel · Aug 02, 2012 at 12:27 AM 0
Share

Thanks, that works perfectly)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fade an image 1 Answer

Pull a color out of a Color.Lerp fade 1 Answer

Color.Lerp not lerping 2 Answers

Changing Alpha Thru Code Acts Weird 1 Answer

Lerping/Fading between multiple colours 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