Here is the code, ik it is very basic:
using UnityEngine;
using System.Collections;
public class FirstPersonController : MonoBehaviour {
public float movementSpeed = 5.0f;
public float mouseSensitivity = 5.0f;
public float upDownRange = 60.0f
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// Rotation
float rotLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;
transform.Rotate(0, rotLeftRight, 0);
float rotUpDown = Input.GetAxis("Mouse Y") * mouseSensitivity;
float currentUpDown = Camera.main.transform.rotation.eulerAngles.x;
float desiredUpDown = currentUpDown - rotUpDown;
Camera.main.transform.rotation = Quaternion.Euler(desiredUpDown, 0, 0);
// movement
float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
Vector3 speed = new Vector3( sideSpeed, 0, forwardSpeed );
speed = transform.rotation * speed;
CharacterController cc = GetComponent<CharacterController>();
cc.SimpleMove( speed );
}
}