Input does't work at all for me
I have am trying this code with default input manager settings. It is attached to a game object with no other components in scene. Its Camera field is setted to default camera in the scene. Each input function returns false/0 no matter what I try. Even Input.anyKeyDown never returns true.
public class KeyboardController : MonoBehaviour
{
public float YMin = -100;
public float YMax = 100;
public float XMin = -100;
public float XMax = -100;
public float XSpeed = 1;
public float YSpeed = 1;
public float MouseXSpeed = 1;
public float MouseYSpeed = 1;
public GameObject Camera;
public void Update()
{
var pos = Camera.transform.position;
var x = pos.x;
var y = pos.y;
if (Input.GetKeyDown(KeyCode.Mouse1))
{
x += MouseXSpeed * Time.deltaTime * Input.GetAxis("Mouse X");
y += MouseYSpeed * Time.deltaTime * Input.GetAxis("Mouse Y");
}
else
{
x += XSpeed * Time.deltaTime * Input.GetAxis("Horizontal");
y += YSpeed * Time.deltaTime * Input.GetAxis("Vertical");
}
if (x < XMin)
x = XMin;
else if (x > XMax)
x = XMax;
if (y < YMin)
y = YMin;
else if (y > YMax)
y = YMax;
Camera.transform.position.Set(x, y, pos.z);
}
}
You should consider changing your account name. Spam filters will block it and moderators who rely on their email to check out questions will never see it.
First thing to do is stick some Debug.Log's in there. It'll instantly show if the issue is not getting input or the rest of the code not working as you expect.
Then consider changing your forum name :D - although it makes me laugh :)
Actually I tested it with both Debug.Logs and break points, it doesn't print/stop there.
O$$anonymous$$ what about trying $$anonymous$$eyCode.$$anonymous$$ouse0
Answer by TBruce · May 26, 2016 at 03:39 PM
KeyCode.Mouse1 refers to the secondary mouse button which in most cases is the right mouse button.
But if using Input.GetKeyDown(KeyCode.Mouse0) (left) / Input.GetKeyDown(KeyCode.Mouse1) (right) is not working for you then I would suggest using
Input.GetButtonDown("Fire1"); (Left)
or
Input.GetButtonDown("Fire2"); (Right)
Also do you always want to be falling into the else block if mouse is not pressed?
Yeah, thx. Anyway I had weird problems with Input cuz of corrupted sytem on dying SSD. It is TBS game with upside down camera, so it's not falling and height is Z there anyway.