Hi.
I’m trying to make a system where if the player hits a specific object, its color changes between 3 predefined colors. However, I want the player to have skins, and I want to give the color only to certain meshes of the children objects.
Right now, what I have is:
private CharacterController controller;
public Material[] colors; //I have already set 3 colors in inspector.
public Renderer[] skins; // I have put all the skins I want to change here, and didn't put any of the skins I don't want to change color.
public int c;
void Start()
{
controller = GetComponent<CharacterController>();
skins = GetComponentsInChildren<Renderer>(); //I think the problem is here, since this gets all the components in children objects.
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.transform.tag == "ChangeColor")
{
Destroy(hit.gameObject);
foreach (Renderer rend in skins)
{
{
c = Random.Range(0, colors.Length);
rend.material = colors
;
}
Any ideas, please?