[Tooltip("严格按照红、黄、绿排序")]
public Material[] colors;
int index = 0;
// Start is called before the first frame update
void Start()
{
ChangeColor();
}
// Update is called once per frame
void Update()
{
}
private void ChangeColor()
{
var mesh = GetComponent<MeshRenderer>();
mesh.material = colors[index];
if (index == 0)
{
Invoke("ChangeColor", 8); //红到黄、间隔8秒
}
else if (index == 1)
{
Invoke("ChangeColor", 3); //黄到绿,间隔3秒
}
else if (index == 2)
{
Invoke("ChangeColor", 5); //绿到黄、间隔5秒
}
index++;
if (index % colors.Length == 0)
{
index = 0;
}
}