Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Mouse Input

AechDub edited this page May 22, 2018 · 4 revisions

The mouse input control allows you to receive over video mouse events.

Creating your control in Studio

Add a mouse control to your project (note, you can only create one per project).

Select a mouse control

Next, adjust the settings to support your needs. There are two adjustable properties:

Send Move Events *mousedown (default) - this will only send mouse move events during a mousedown event

  • always - mouse move events are sent on hover and during mousedown
  • never - never send mouse move events. You will still receive click events.

Move Throttle You can also adjust mouse move event throttling. The moveThrottle duration, given in milliseconds, will throttle movement events sent to the game client. The default is 50ms.

Mouse control properties

Mouse Click

If you want to get click events, you can write something such as the following:

if (MixerInteractive.GetMouseButton())
{
    if (Physics.Raycast(Camera.main.ScreenPointToRay(MixerInteractive.MousePosition), out hit, 100))
    {
        target = hit.point;
    }
}

Mouse Move

If you want to get mouse move events, you can write something such as the following:

float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target, step);
RaycastHit hit;

if (Physics.Raycast(Camera.main.ScreenPointToRay(MixerInteractive.MousePosition), out hit, 100))
{
    target = hit.point;
}

Alternatively, you can listen directly to the coordinates change event like so:

MixerInteractive.OnInteractiveCoordinatesChangedEvent += MixerInteractive_OnInteractiveCoordinatesChangedEvent;
...

private void MixerInteractive_OnInteractiveCoordinatesChangedEvent(object sender, Microsoft.Mixer.InteractiveCoordinatesChangedEventArgs e)
{
    string viewName = e.Participant.UserName;
    RaycastHit hit;

    if (Physics.Raycast(Camera.main.ScreenPointToRay(e.Position), out hit, 100))
    {
        Debug.Log("HitPoint " + hit);
    }
}