skip to Main Content

Unit Selection Events

Check demo scene 509

When you call WMSK_MoveTo() method to move an unit to the viewport, it received a BoxCollider component if it doesn’t already contain their own collider (this collider component is responsible for triggering internal events produced by mouse hovering and clicking on them – if the collider is destroyed, the unit will be no longer selectable).

The following 4 events exposed by the GameObjectAnimator component can be used to detect mouse events:

OnPointerEnter: triggered when the mouse enters the gameobject.

OnPointerExit: triggered when the mouse abandon the gameobject.

OnPointerDown: triggered once when mouse left button is pressed over the gameobject.

OpPointerUp: triggered when the left mouse left button is released on the gameobject.

OnPointerRightDown: triggered once when mouse right button is pressed over the gameobject.

OpPointerRightUp: triggered when the mouse right button is released on the gameobject.

For example, if you want to receive events from a specific unit “tank1” you do:

tank1.OnPointerEnter += (GameObjectAnimator anim) => Debug.Log ("Tank1 mouse enter event.");

The above events are useful at individual unit level, but there’re also 4 global actions that you can use to detect mouse interactions with any unit. These global actions are defined in WMSKViewportGameObject.cs:

Action<GameObjectAnimator> OnVGOPointerEnter; (Mouse enters the gameobject)

Action<GameObjectAnimator> OnVGOPointerExit; (Mouse abandon the gameobject)

Action<GameObjectAnimator> OnVGOPointerDown; (Left mouse button pressed on the gameobject)

Action<GameObjectAnimator> OnVGOPointerUp; (Left mouse button released on the gameobject)

Action<GameObjectAnimator> OnVGOPointerRightDown; (Right button pressed the gameobject)

Action<GameObjectAnimator> OnVGOPointerRightUp; (Right button released on the gameobject)

You can assign your own delegate method to these actions and it will receive the reference to the GameObjectAnimator that generated the mouse event. This way you can have a single point or global approach to mouse event handling for all units. Remember that the GameObjectAnimator is nothing more than a component attached to the unit gameobject.

For example if you want to receive a mouse event for any unit you do:

map.OnVGOPointerDown = delegate(GameObjectAnimator obj) {
      Debug.Log ("Mouse button pressed on " +;
Back To Top