Simple way to incorporate Player movement

When asked to stop the video and come up with a PlayerController script, I did and played around with it for awhile before coming up with my take on the controls, which actually works very well and publicly exposes the speed in the editor for change. Here it is:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    public float speed = 2.5f;
    
    void Update () {
        if (Input.GetKey(KeyCode.LeftArrow)) {
            transform.position += Vector3.left * speed * Time.deltaTime;
        } else if (Input.GetKey(KeyCode.RightArrow)){
            transform.position += Vector3.right * speed * Time.deltaTime;
        }
    }
    
}

Privacy & Terms