- Home /
How to change leaf textures over time (For changing seasons)
Does anyone know how to change a leaf texture from spring to summer to fall and then to winter using a timer? For example I would need a code that makes a timer for days/months/years and every 45ish days it changes some textures for a season transition. I have been looking on google and the forums for a way to do this but to no success.
Do you want smooth transition, or should they just change instantly after some days have passed?
Do you have any solution that you think should work? If yes then you could share it so it's easier for us to understand how your leafes work.
What do you want to change? A material? Texture in that material? Or are your leafes sprites?
Answer by ValakhP · Oct 24, 2018 at 09:37 AM
Hello Lebraz.
Well, you can use different materials for your model. In each material there will be different textures with different leaf colors. All you'll need - just replace material at the right moment:
meshRenderer.material = anotherMaterial;
Another option - just replace texture for your material:
meshRenderer.material.SetTeture("_MainTex", anotherTexture");
Thank you ValakhP! How would I sync that to a timer? Is it possible to use an if statement? Im very new to coding in c#.
You can create the timer as $$anonymous$$onoBehaviour object with Update method that increments its time field by Time.deltaTime each Update call. So your time field will be time in seconds from the moment you created the object.
But it'd be better to make a research in a direction of Unity Coroutines or async C# methods.
Thank you so much for helping! I have absolutely no idea what that means or how I would use that for a texture swap but I will research it! Thanks again!
Your answer
Follow this Question
Related Questions
Timer reset 1 Answer
Making a texture 2 Answers
Sprite Manager 2 - Change Texture of a gameObject 1 Answer
Changing texture on prefab at runtime (c#) 1 Answer
Generate textures from folder of images 0 Answers