Goady
Goady

Reputation: 39

How do I use MouseUtils in C#?

public MouseUtils.Button respondToMouseButton = MouseUtils.Button.Left;

public void OnMouseOver() {
    if(Input.GetMouseButtonDown((int)respondToMouseButton))
        Destroy(this.gameObject);

I am getting an error saying that MouseUtils doesn't exist, though I've gotten this from a Unity 4 tutorial, where it seemed to work fine.

Thanks in advance.

Upvotes: 0

Views: 102

Answers (2)

Nathan Kummel
Nathan Kummel

Reputation: 98

You've missed the class:

 public class MouseUtils {
    public enum Button : int { Left = 0, Right = 1, Middle = 2, None = 3 };
}

Upvotes: 1

Alox
Alox

Reputation: 671

Why not simply pass an int without casting a MouseUtils.Button?

https://docs.unity3d.com/ScriptReference/Input.GetMouseButtonDown.html

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        if (Input.GetMouseButtonDown(0))
            Debug.Log("Pressed left click.");

        if (Input.GetMouseButtonDown(1))
            Debug.Log("Pressed right click.");

        if (Input.GetMouseButtonDown(2))
            Debug.Log("Pressed middle click.");

    }
}

Upvotes: 1

Related Questions