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 /
avatar image
0
Question by Lebraz · Oct 24, 2018 at 05:27 PM · timertextures

Changing leaf colors in C#

So, I have a few ideas for this but I don't know how to directly change the textures of a leaf on a tree using: using UnityEngine; using System.Collections;

public class SimpleTimer: MonoBehaviour {

public float targetTime = 60.0f;

Update(){

targetTime -= Time.deltaTime;

if (targetTime <= 0.0f) { timerEnded(); }

}

void timerEnded() { meshRenderer.material.SetTeture("_MainTex", anotherTexture"); }

}

How could i make this work?? Also, I have little to none experience in c# or unity in general. Thanks!

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

Answer by Bleakmountain50 · Oct 25, 2018 at 12:04 AM

if you give every leaf a tag called "Leaf" then this should work:

 public float targetTime = 60.0f;
 public Material leafColor;

 void Update()
 {
     if (targetTime > 0)
     {
         targetTime -= Time.deltaTime;
     }

     if (targetTime <= 0.0f)
     {
         targetTime = 0.0f;
         timerEnded();
     }

 }

 void timerEnded()
 {
    var leaf = GameObject.FindGameObjectWithTag("Leaf");
     leaf.GetComponent<Renderer>().material = leafColor;
 }
 

}

make a material that you want to be the leaf material and put it in the slot

SIDENOTE: I also made a change to the time so it stops ticking after it hits 0 :)

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 Lebraz · Oct 25, 2018 at 04:07 AM 0
Share

That is unbelievably helpful! How would i select each leaf/gave each leaf the tag "Leaf" if i imported the tree from blender? i haven't gotten time to try this but I want to be sure im doing everything right so I don't screw anything up, yet again thank you!

avatar image Bleakmountain50 Lebraz · Oct 25, 2018 at 07:05 PM 1
Share

If you imported it from blender i don't know. usually there is a part of the tree that has the leaves attached to it. if you're able to put the script directly on the leaves then put in this script:

  public float targetTime = 60.0f;
  public $$anonymous$$aterial leafColor;
  void Update()
 {
      if (targetTime > 0)
      {
          targetTime -= Time.deltaTime;
      }
      if (targetTime <= 0.0f)
      {
          targetTime = 0.0f;
          timerEnded();
      }    
  }
  void timerEnded()
  {
 
      gameObject.GetComponent<Renderer>().material = leafColor;
  }

if you need anymore instruction/help on this message me on discord at: Bleakmountain50#1450

avatar image Lebraz Bleakmountain50 · Oct 26, 2018 at 01:53 AM 0
Share

I have just sent you a friend request, I need some major help. Thanks again!!

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

96 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

Related Questions

How to create Timer animations? 1 Answer

How to make a random occurrences using a timer? 3 Answers

Countdown timer with textures ? 1 Answer

Convert this string formatting from C# to JS 1 Answer

Start timer with trigger 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