I need a code that changes the color of all of my game objects (not sprites), but not all to the same color (each object must have a random color). I made a code that asigns the same random color to all of the game objects(not sprites). And i cannot figure this out, i am struggling with this for several hours now, really annoying! Heres the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RandomizeColors : MonoBehaviour
{
Vector4[] colors = { new Vector4(1, 0, 0, 1), new Vector4(0, 1, 0, 1),
new Vector4(0, 0, 1, 1), new Vector4(0, 1, 1, 1), new Vector4(1, 0, 1, 1),
new Vector4(1, 1, 0, 1) };
private Vector4 RandomColor()
{
Vector4 color = colors[Random.Range(0, colors.Length)];
return color;
}
private void Update()
{
GetComponent<Image>().material.color = RandomColor();
}
}