# Highlight 3D objects

**URL:** https://discussions.unity.com/t/highlight-3d-objects/929577
**Category:** Scripting
**Tags:** Scripting, Question
**Created:** [September 20, 2023, 5:03pm UTC](https://discussions.unity.com/t/highlight-3d-objects/929577 "2023-09-20T17:03:53Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Deivydas4](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/deivydas4/32/86087_2.png) [@Deivydas4](https://discussions.unity.com/u/Deivydas4)
#### Post date: [September 20, 2023, 5:03pm UTC](https://discussions.unity.com/t/highlight-3d-objects/929577/1 "2023-09-20T17:03:53Z")

</div>

Hello, Unity community!

How can I make an object change its emission to green when I hover my mouse over it, and ensure that it stays selected (green) even after I click it? Does anyone know how to achieve this?

```csharp
public class Interaction : MonoBehaviour
{
    [SerializeField] private Renderer rend;
    private Color color = new Color32(31, 103, 39, 255);
    private List<Material> materials;
    bool isHighlighted;

    private void Awake()
    {
        materials = new List<Material>();
        materials.AddRange(rend.materials);
    }

    public void ToggleHighlight(bool value)
    {
        if (value)
        {
            foreach (var mat in materials)
            {
                mat.EnableKeyword("_EMISSION");
                mat.SetColor("_EmissionColor", color * 1);
            }
        }
        else
        {
            foreach (var mat in materials)
            {
                mat.DisableKeyword("_EMISSION");
            }
        }
    }

    private void OnMouseEnter()
    {
        ToggleHighlight(true);
    }

    private void OnMouseExit()
    {
        ToggleHighlight(false);
    }
}

```

Thank you!

---

<div class="post-metadata">

### Author: ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)
#### Post date: [September 20, 2023, 5:06pm UTC](https://discussions.unity.com/t/highlight-3d-objects/929577/2 "2023-09-20T17:06:57Z")

</div>

> [@Deivydas4](#):
>
> materials.AddRange(rend.materials);

Materials materials array of materials renderer:

Generally accessing .material / .materials is going to give you a fresh copy. (See docs for why and when)

[https://discussions.unity.com/t/789181/5](https://discussions.unity.com/t/789181/5)

[https://discussions.unity.com/t/826696/5](https://discussions.unity.com/t/826696/5)
