Search Unity

mouseover?

Discussion in 'Scripting' started by cranko, Jul 24, 2005.

  1. cranko

    cranko

    Joined:
    Jul 24, 2005
    Posts:
    4
    Trying to do some basic stuff like mouseover. I see how to get the mouse position, but how to i tell if the mouse is intersecting an object on the screen?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    The easy way is like this.

    Code (csharp):
    1.  
    2. function OnMouseOver ()
    3. {
    4.   renderer.material.color = Color.red;
    5. }
    6.  
    You have to attach the script to the Object you want the mouse over event to receive. The object has to have a collider otherwise it wont work.


    If you want full control you can use raycasting for this.

    Take a look at the Script Tutorial folder. It covers script examples like this.
    eg. /Users/Shared/Unity/Script Tutorial/Assets/LaunchProjectileMouse.js