Search Unity

Detect OnMouseOver on attached Transforms

Discussion in 'Scripting' started by INKnightStudio, May 5, 2018.

  1. INKnightStudio

    INKnightStudio

    Joined:
    Sep 4, 2015
    Posts:
    9
    How I can detect when my mouse are over attached Transforms on script?
    I have an Transform variable on my script, and I need to detect when mouse is over it.
     
  2. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    494
    If it's the transform the script is on just use OnMouseOver. If it's transforms that are child objects of the transform the script is on have a script on each of them with OnMouseOver in it and have that script tell the script on the parent object that the mouse is over it by doing something like changing a bool in the parent transforms script. You would probably want to let the main script know when the mouse is no longer over one of the child transforms though and having them all turning one bool on and off could potentially cause problems in which case having a list of bools corresponding to each individual child script and having the parent transforms script check the whole list might be the best way to go.

    https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html
     
    INKnightStudio likes this.