i started recently learning the unity basics and programmin (about 4 weeks ago) and i’m enjoying it very much, usually whenver i’m stuck i search on the internet and i find a solution everytime but this time i didn’t find anyone encountered the same problem as me so here my problem . i made a movement script to my 2d character using c# , it worked fine but to make my character move i have to click the key everytime and if i keep holding it he won’t move .
public class NinjaMovement : MonoBehaviour
{
public float speed = 3f;
public Rigidbody2D rb;
public float jump = 2f;
void awake ()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
// ...moving left
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Debug.Log(rb);
rb.velocity = new Vector2(speed * -1,rb.velocity.y);
}
//...moving right
if (Input.GetKeyDown(KeyCode.RightArrow))
{
Debug.Log(rb);
rb.velocity = new Vector2(speed , rb.velocity.y);
}
//...jumping
if (Input.GetKeyDown(KeyCode.UpArrow))
{
rb.velocity = new Vector2(jump, rb.velocity.x);
}
}
}