I can’t get my square to move. I want to be able to use the A and D keys to move my player (the square). This is what I currently have:
Edit: This is what I now have, and I can move my player, but i can only move it a little bit per keypress. Is there a way i can make it so that I constantly move, for as long as A or D is held down?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Sprites;
public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody2D rb;
void Update () {
if (Input.GetKeyDown (KeyCode.A))
{
transform.Translate (-Vector3.right * Time.deltaTime * speed);
}
if (Input.GetKeyDown (KeyCode.D))
{
transform.Translate (-Vector3.right * Time.deltaTime * speed);
}
}
}