Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ColorChanger : MonoBehaviour {
- private Renderer m_Renderer;
- private Color32[] colors;
- private Color32 g; /*The Green Color*/
- private Color32 r; /*The red color*/
- private Color32 y; /*The yellow color*/
- private Color32 m_NormalColor; /*The color I should have by default*/
- void Start()
- {
- m_Renderer = GetComponent<Renderer>();
- g = new Color32(63, 207, 67, 0);
- y = new Color32(214, 219, 51, 0);
- r = new Color32(202, 39, 39, 0);
- colors = new Color32[] { g, y, r };
- m_NormalColor = colors[Random.Range(0, colors.Length)];
- GetComponent<Renderer>().material.color = m_NormalColor;
- }
- void Update()
- {
- // TESTING ONLY, REMOVE FOR REAL BUILD
- if (Input.GetKeyDown(KeyCode.Space))
- {
- GetComponent<Renderer>().material.color = colors[Random.Range(0, colors.Length)];
- }
- }
- //Run your mouse over the GameObject to change the Renderer's material color to red
- void OnMouseOver()
- {
- Debug.Log("Mouse is over this object!", gameObject)
- m_Renderer.material.color = Color.white;
- }
- //Change the Material's Color back to white when the mouse exits the GameObject
- void OnMouseExit()
- {
- Debug.Log("Mouse is no longer over this object!", gameObject)
- m_Renderer.material.color = m_NormalColor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement