I am new to unity so forgive me if i get any technical words wrong…I have quickly made a simple code from my original to try make it easier to look at.
So my purpose is to change the color of my gameobject with the help of my color picker panel. However, once i hit the play button the two gameobjects (cube) goes to the the first index of my colour picker. What i want is the gameobject cubes to start of as the original materiel and only change color if the user selects what color they want from the color picker panel. How could i make that possible?
In the bigger picture ive got another model created with it own original color but once i hit the play button the model goes to the first color of the color array within the panel i made. For example, a character will have a red hate, white top and red shoes with a color array from panel created of green[0], grey[1], blue[2]. When i hit the play button the character colors will go all green instead of showing the default material colors.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ColourChange : MonoBehaviour
{
public GameObject panel;
public GameObject cube;
public GameObject panelR;
public GameObject cubeR;
public Color[] colors;
public Color[] colorsR;
public int whatColor = 1;
public int whatColorR = 1;
void Update(){
for (int i = 0; i < colors.Length; i++){
if(i == whatColor){
cube.GetComponent<Renderer>().material.color = colors[i];
}
}
for (int i = 0; i < colorsR.Length; i++){
if(i == whatColorR){
cubeR.GetComponent<Renderer>().material.color = colorsR[i];
}
}
}
public void ChangePanelState(bool state){
panel.SetActive(state);
}
public void ChangePanelRState(bool state){
panelR.SetActive(state);
}
public void ChangeCubeColor(int index){
whatColor = index;
}
public void ChangeCubeRColor(int index){
whatColorR = index;
}
}