New to enum.

enum MouseState {Left, Right, Middle}

public class PlayerManager : MonoBehaviour 
{
	void Update () 
	{
		if(Input.GetButtonDown(MouseState.Left))
		{
			Debug.Log("Left Clicked");	
		}
	}

I am using enum for the first time. Here the value of enum variables shhould be Left =0, Right =1, Middle =2.

But when I am writing Input.GetButtonDown(MouseState.Left) it gives an error saying that cannot convert ‘MouseButton’ expression to type string.

From what I have learned MouseState.Left should be = 0.

Am I Wrong? Is there any other solution for this?

2 Answers

2

Even though it is 0, you need to cast it into integer:

if(Input.GetButtonDown((int)MouseState.Left))

And in addition it should be Input.GetMouseButtonDown because Input.GetButtonDown only takes a string parameter and it should be the name of a virtual input defined in the inputmanager.

–

Oh and btw: When you use <a href="http://docs.unity3d.com/Documentation/ScriptReference/Input.GetKeyDown.html">Input.GetKeyDown</a> you can use [Keycode.Mouse0][1] up to [Keycode.Mouse6][2] [1]: http://docs.unity3d.com/Documentation/ScriptReference/KeyCode.Mouse0.html [2]: http://docs.unity3d.com/Documentation/ScriptReference/KeyCode.Mouse6.html

–

Thanks for your answer.... it helped me a lot

–

Mark it as correct if it is so.

–

HI I had answered a similar question here [execpt it is Javascript]