ForwardAllMouseEvents

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<csharp>" to "<syntaxhighlight lang="csharp">")
m (Text replace - "</csharp>" to "</syntaxhighlight>")
 
Line 51: Line 51:
 
     }
 
     }
 
}
 
}
</csharp>
+
</syntaxhighlight>

Latest revision as of 20:45, 10 January 2012

Author: Jonathan Czeck (aarku)

Contents

[edit] Description

This script will send mouse events to a target GameObject.

[edit] 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.

[edit] Advanced Usage

See DraggableGUIElement.

[edit] C# - ForwardAllMouseEvents.cs

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);
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox