Holding down right arrow but only moving once

Hi,

when I play my game and hold a key pressed my object wil only move once as if I only pressed it once.
Someone knows a fix for this?

Thank you

PS: srry I didn’ t know why my top part of the code isn’ t in the box…


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class shipMovement : MonoBehaviour {
public float speed = 10.0f;

void Update (){
	if (Input.GetKeyDown (KeyCode.RightArrow)){
		transform.position += new Vector3(speed*Time.deltaTime, 0,0);
		print("R arrow down");
	}else if(Input.GetKeyDown (KeyCode.LeftArrow)){
		transform.position += new Vector3(-speed*Time.deltaTime, 0, 0);
		print("L arrow down");
	}
}

}

He Elias,

You want to use Input.GetKey() instead of Input.GetKeyDown().
GetKeyDown only returns true if the key was pressed down during that frame.

2 Likes

Thank you!!!!!!

Privacy & Terms