Keypress Left is called twice in Update when key is pressed only once
- by Simran kaur
I have a piece of code that is changing the position of player when left key is pressed. It is inside of Update() function. I know, Update is called multiple times, but since I have an ifstatement to check if left arrow is pressed, it should update only once. I have tested using print statement that once pressed, it gets called twice.
Problem:
Position updated twice when key is pressed only once.
Below given is the structure of my code:
void Update()
{
if (Input.GetKeyDown (KeyCode.LeftArrow))
{
print ("PRESSEEEEEEEEEEEEEEEEEEDDDDDDDDDDDDDD");
}
}
I looked up on web and what was suggested id this:
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.LeftArrow)
{
print("pressed");
}
But, It gives me an error that says:
Object reference not set to instance of an object
How can I fix this?