I’m trying to move a character by holding down the arrow keys, but it’s not working. When I go without Time.deltaTime and just press the arrow keys it works fine. I want to move my character more precisely by holding down the arrow keys.
Help?
This is the code I’m using:
using UnityEngine;
using System.Collections;
public class Ctrl : MonoBehaviour
{
public float speed = 1.5f;
void Update ()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.position += Vector3.left * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.UpArrow))
{
transform.position += Vector3.up * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow))
{
transform.position += Vector3.down * speed * Time.deltaTime;
}
}
}