how to make a cube change color by clicking a button?
i want to change the color of the cube by clicking on a button. i have 3 buttons and one cube. so by clicking on each button the cube should change color according to that. how to do it? i have used a script:-
Blockquote
using UnityEngine;
using System.Collections;
// Change renderer's material each changeInterval
// seconds from the material array defined in the inspector.
public class color2 : MonoBehaviour
{
public Material[] materials;
public float changeInterval = 0.33F;
public Renderer rend;
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
}
public void Update()
{
if (materials.Length == 0)
return;
// we want this material index now
int index = Mathf.FloorToInt(Time.time / changeInterval);
// take a modulo with materials count so that animation repeats
index = index % materials.Length;
// assign it to the renderer
rend.sharedMaterial = materials[index];
}
}
i have added this script to a cube and i have dragged and dropped this game object(cube) to button and triggered the function void update(). if i pressed a button its not working? how to solve this?][1]][1]][1]
Comment