Hey, I made a script for object to change colors. so when I press E on keyboard it change the color of the object according to the numbers of color i defined. the problem is that I don’t know how to make it repeat on the process. lets say I made 3 colors. at the beginning it shows me the first color, by pressing E it change to the second color, another press on E and it change to the third color and that’s it, after pressing again on E nothing happening. how can I make it to return to the first color by the fourth click, and loop the process? thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class colorchNGE : MonoBehaviour
{
public Material[]Materials;
public Renderer rend;
private int index = 1;
// Start is called before the first frame update
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
}
private void Update()
{
if (Materials.Length == 0)
{
return;
}
if (Input.GetKeyDown(KeyCode.E))
{
index += 1;
}
print(index);
rend.sharedMaterial = Materials[index - 1];
}
}