Hoping to get some guidance

While viewing this video it dawned on me to use a mouseOver event.

I haven’t finished it at all only tested that it works when mouse is over.

My question is would this approach lead to worse preformance?

Hers the script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseOverPopUps : MonoBehaviour
{
    [SerializeField] string popUpMessage = "Enter text caption for this popup";

    void OnMouseOver()
    {
        //If your mouse hovers over the GameObject with the script attached, output this message
        Debug.Log($"Mouse is over GameObject: {this.name} and its tag is {this.gameObject.tag}");
    }

    void OnMouseExit()
    {
        //The mouse is no longer hovering over the GameObject so output this message each frame
        Debug.Log($"Mouse is no longer on GameObject: {this.name} and its tag is {this.gameObject.tag}");
    }
    
}

Thanks for feedback

Oh yea forgot to mention

I have been testing it on pickups… no errors but I wonder pros and cons of doing it this way?

Thanks

I’m honestly not sure what the performance hit for using OnMouseOver() is…

A quick technical note on the comment for OnMouseExit()… OnMouseExit() will only fire once, when the mouse leaves the GameObject, not every frame.

  • OnMouseEnter() - Fires once when mouse goes over the GameObject
  • OnMouseOver() - Fires continuously while mouse is over GameObject
  • OnMouseExit() - Fires once when mouse leaves GameObject

Privacy & Terms