Problem with FindAllObjectsWithTag

See second post for edited code, and issue. Thanks :slight_smile:

I’ve cleaned the code and narrowed this to a single bug. Not sure what it is. The button is blinking on and off. I find OnMouseEnter, and OnMouseExit to be touchy for some reason.

btn_script

using UnityEngine;
using System.Collections;

public class btn_script : MonoBehaviour {

    public GameObject btn;
    public GameObject highlightBtn;

    private bool highlighted;

    private GameObject highlightedID;

    // Use this for initialization
    void Start () {

        highlighted = false;

    }
   
    // Update is called once per frame
    void Update () {
   

        if (highlighted && highlightedID == null) {
           
            highlightedID = (GameObject)Instantiate (highlightBtn, new Vector3 (btn.transform.position.x, btn.transform.position.y, 0f), transform.rotation);
           
        } else {

                Destroy (highlightedID);

        }

        // End update
    }

    void OnMouseDown()
    {

        // Left clicked menu button
        if (Input.GetMouseButton (0)) {
            if(name.Contains("btn_close"))
            {

                // Remove hover from all menu buttons
                GameObject[] objects = GameObject.FindGameObjectsWithTag("floor_item");

                foreach(GameObject item in objects)
                {
                   
                    if(item.GetComponent<HoverMenu>() != null)
                    {

                        item.GetComponent<HoverMenu>().clear();
                       
                    }
                   
                }

                // End if button close clicked
            }
           
           
            // End left clicked menu button
        }


    }

    void OnMouseOver()
    {

        // count all opened menues
           
        highlighted = true;

        // End OnMouseOver
    }

    void OnMouseExit()
    {

        highlighted = false;

    }

}