Lebraz
October 24, 2018, 5:27pm
1
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!
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