Note: This is my second day using Unity and I’m not familiar with C#.
Each color is a button using a background image.
How can I assign a color to each button and make them change the color of the car?
Note: This is my second day using Unity and I’m not familiar with C#.
Each color is a button using a background image.
How can I assign a color to each button and make them change the color of the car?
using UnityEngine;
using System.Collections;
public class ButtonColorChanger : MonoBehaviour
{
[SerializeField]
public Color color;
[SerializeField]
private GameObject targetObject;
public void SetColor()
{
if(targetObject == null)
{
Debug.LogError("Traget Object is not assigned!");
return;
}
Renderer objectRenderer = targetObject.GetComponent<Renderer>();
if(objectRenderer == null)
{
Debug.LogError("Traget Object has no renderer!");
return;
}
Material mat = objectRenderer.material;
mat.color = color;
}
}
Attach this script to each button, select your car model as target object and pick proper collors. Make buttons call SetColor() method of this script.
Keep in mind that you have to learn C# and Unity.