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 Eric 8 · Sep 09, 2010 at 05:11 PM · materialcolortreeanimate

Changing Color of Tree Material

SO what I'm trying to do is Put some trees in my scene. I'm using a default tree from a Unity Package, the tree called Sycamore (With Collider). In the Inspector window I can change the color of the material for the leaves. What I want to do, is to figure out how to get the material for the leaves to animate, meaning as I play the game have the leaves start out green, go yellow, orange, red, then back again continuously. Does anyone have any idea how I can set that up? I'm pretty new to Unity and know next to nothing about scripting, though any suggestions would be greatly appreciated!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by joedrigon · Sep 09, 2010 at 06:48 PM

Maybe check out the Unity reference for material below...

link text

// Fade the color from red to green // back and forth over the defined duration var colorStart = Color.red; var colorEnd = Color.green; var duration = 1.0;

function Update () { var lerp = Mathf.PingPong (Time.time, duration) / duration; renderer.material.color = Color.Lerp (colorStart, colorEnd, lerp); }

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 Eric 8 · Sep 13, 2010 at 07:58 PM 0
Share

Wow this really helped, thanks a lot! It works! Now I just have to figure out how to get it to affect the right part of the tree lol. It's effecting park of the trunk, but not all of it, and not affecting the leaves.

avatar image Eric 8 · Sep 14, 2010 at 12:26 AM 0
Share

This should be posted as a comment to the answer, and not a separate answer.

avatar image Eric 8 · Sep 13, 2010 at 08:09 PM 0
Share

Oops never$$anonymous$$d I got it! Thanks again!

avatar image Eric 8 · Sep 14, 2010 at 12:27 AM 0
Share

If you've received a helpful answer, remember to upvote it (click the up arrow next to it), and if it solved your problem, tick the box below the up/down arrows to mark it as the correct answer. This helps to keep UnityAnswers easy to use, and the best answers near the top to assist other users with the same question!

avatar image MMOERPG Eric 8 · May 01, 2014 at 02:07 AM 0
Share

How did you change the color of the leaves? I can only change the trunk color.

avatar image
0

Answer by getyour411 · May 01, 2014 at 02:40 AM

This old post was recently updated so I looked at it too. The issue is that the Sycamore has two materials and the proposed solution only chooses the first (the trunk).

You just need to change this line

 renderer.material.color = Color.Lerp (colorStart, colorEnd, lerp);

to this

     renderer.materials[1].color = Color.Lerp (colorStart, colorEnd, lerp);

Since there is more than one material, just change it to reference to materials and add the [1] bit. I tested this on the Sycamore w/ Collider tree and the leaves changed.

Be aware that if you are building this functionality in the hopes of later moving it to your Terrain trees, that won't work. I posted something about that awhile back and the code is pretty bad but at least it shows an idea

http://answers.unity3d.com/questions/521056/access-terrain-tree-material-from-script.html

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

2 People are following this question.

avatar image avatar image

Related Questions

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

Changing two different objects renderer colour 1 Answer

Adding a Color Change Script to a Model 1 Answer

How to get color from a Tree for Tree Instance? 0 Answers

How to change leave color at runtime? 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