ForwardAllMouseEvents

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by Aarku)
Line 1: Line 1:
 +
[[Category: C Sharp]]
 +
[[Category: MonoBehaviour]]
 +
[[Category: GUI]]
 +
Author: Jonathan Czeck (aarku)
 +
==Description==
 +
This script will send mouse events to a target GameObject.
  
 +
==Usage==
 +
Assign this script to an object with a Collider, GUITexture, or GUIText.  Then set the target property to the GameObject you want the mouse events forwarded to.
 +
 +
==Advanced Usage==
 +
See [[DraggableGUIElement]].
 +
 +
==C# - ForwardAllMouseEvents.cs==
 +
 +
<csharp>using UnityEngine;
 +
using System.Collections;
 +
 +
public class ForwardAllMouseEvents : MonoBehaviour
 +
{
 +
    public GameObject target;
 +
   
 +
    void OnMouseEnter()
 +
    {
 +
        target.SendMessage("OnMouseEnter", null, SendMessageOptions.DontRequireReceiver);
 +
    }
 +
   
 +
    void OnMouseOver()
 +
    {
 +
        target.SendMessage("OnMouseOver", null, SendMessageOptions.DontRequireReceiver);
 +
    }
 +
 +
    void OnMouseExit()
 +
    {
 +
        target.SendMessage("OnMouseExit", null, SendMessageOptions.DontRequireReceiver);
 +
    }
 +
 +
    void OnMouseDown()
 +
    {
 +
        target.SendMessage("OnMouseDown", null, SendMessageOptions.DontRequireReceiver);
 +
    }
 +
 +
    void OnMouseUp()
 +
    {
 +
        target.SendMessage("OnMouseUp", null, SendMessageOptions.DontRequireReceiver);
 +
    }
 +
 +
    void OnMouseDrag()
 +
    {
 +
        target.SendMessage("OnMouseDrag", null, SendMessageOptions.DontRequireReceiver);
 +
    }
 +
}
 +
</csharp>

Revision as of 19:11, 19 October 2009

Author: Jonathan Czeck (aarku)

Contents

Description

This script will send mouse events to a target GameObject.

Usage

Assign this script to an object with a Collider, GUITexture, or GUIText. Then set the target property to the GameObject you want the mouse events forwarded to.

Advanced Usage

See DraggableGUIElement.

C# - ForwardAllMouseEvents.cs

<csharp>using UnityEngine; using System.Collections;

public class ForwardAllMouseEvents : MonoBehaviour {

   public GameObject target;
   
   void OnMouseEnter()
   {
       target.SendMessage("OnMouseEnter", null, SendMessageOptions.DontRequireReceiver);
   }
   
   void OnMouseOver()
   {
       target.SendMessage("OnMouseOver", null, SendMessageOptions.DontRequireReceiver);
   }
   void OnMouseExit()
   {
       target.SendMessage("OnMouseExit", null, SendMessageOptions.DontRequireReceiver);
   }
   void OnMouseDown()
   {
       target.SendMessage("OnMouseDown", null, SendMessageOptions.DontRequireReceiver);
   }
   void OnMouseUp()
   {
       target.SendMessage("OnMouseUp", null, SendMessageOptions.DontRequireReceiver);
   }
   void OnMouseDrag()
   {
       target.SendMessage("OnMouseDrag", null, SendMessageOptions.DontRequireReceiver);
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox