Another way to indicate a GameObject can be interacted with using the mouse is to just change the Albedo color of the material, rather than swapping to a new material. To illustrate this, we can have one color for mouseover and a second color for a mouse click.
Do the following:
- Remove the scripted MouseOverSwap from the Cube GameObject.
- Create a new C# script class called MouseOverDownHighlighter and add an instance object as a component to Cube:
using UnityEngine;
public class MouseOverDownHighlighter : MonoBehaviour {
public Color mouseOverColor = Color.yellow;
public Color mouseDownColor = Color.green;
private Material _originalMaterial;
private Material _mouseOverMaterial;
private Material _mouseDownMaterial;
private MeshRenderer _meshRenderer;
private bool _mouseOver = false;
void Awake()
{
_meshRenderer = GetComponent<MeshRenderer>();
_originalMaterial = _meshRenderer...