Hello, I am quite new to Unity in general and was wondering how I can this movement script move the object until I let go of the key.
So far, if I hold A or W, it moves the object 1 step at the desired speed, but only once. I have to let go of the key and press it again to repeat the process.
using UnityEngine;
using System.Collections;
public class controlScript : MonoBehaviour {
//Variable declaritions
static float speed = 5;
static float step = 1;
private Vector3 pos;
void Start () {
pos = transform.position;
}
//Actual Control
void Update () {
if (Input.GetKeyDown(KeyCode.D))
{
pos.x += step;
}
if (Input.GetKeyDown(KeyCode.A))
{
pos.x -= step;
}
transform.position = Vector3.MoveTowards(transform.position, pos, speed * Time.deltaTime);
}
}
Thank you in advance