Based on cjmarsh pointer I came up with the following thought I would post it here in case others came looking for similar.
Note I capture the start color but you could in most cases assume that a mats base color is white I suppose I have a few points where I am using the mat color to tent my meshes so I needed to know what it was before the mouse entered. As to the boolean testing; unnecessary to stack them like that its done for clarity in this case.
using UnityEngine;
using System.Collections;
public class MouseEventHandler : MonoBehaviour {
private Color StartColor;
public Color MouseOverColor = Color.yellow;
// Use this for initialization
void Start ()
{
if(renderer != null)
if(renderer.material != null)
StartColor = renderer.material.color;
}
// Update is called once per frame
void Update () {
}
void OnMouseEnter()
{
if(renderer != null)
if(renderer.material != null)
renderer.material.color = MouseOverColor;
}
void OnMouseOver ()
{
}
void OnMouseExit()
{
if(renderer != null)
if(renderer.material != null)
renderer.material.color = StartColor;
}
}
↧