using UnityEngine;
using System.Collections;
[RequireComponent (typeof(CharacterController))]
public class FirstPersonController : MonoBehaviour {
public float movementspeed = 5.0f;
public float sidespeed = 3.0f;
public float UpDownRange = 60.0f;
public float mousespeed = 2.0f;
public float jumpSpeed = 2.0f;
float verticalRotation = 0;
float VerticalVelocity = 0;
CharacterController characterController;
// Use this for initialization
void Start () {
Screen.lockCursor = true;
CharacterController characterController = GetComponent ();
Debug.Log(characterController);
}
// Update is called once per frame
void Update () {
//rotation
float rotLeftRight = Input.GetAxis (“Mouse X”) * mousespeed;
transform.Rotate (0, rotLeftRight, 0);
verticalRotation -= Input.GetAxis (“Mouse Y”) * mousespeed;
verticalRotation = Mathf.Clamp (verticalRotation, -UpDownRange, UpDownRange);
Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0);
//movement
float forwardSpeed = Input.GetAxis(“Vertical”) * movementspeed;
float sideSpeed = Input.GetAxis(“Horizontal”) * sidespeed;
VerticalVelocity += Physics.gravity.y * Time.deltaTime;
if( characterController.isGrounded Input.GetButtonDown(“Jump”) ) {
VerticalVelocity = jumpSpeed;
}
Vector3 speed = new Vector3 ( sideSpeed, VerticalVelocity, forwardSpeed );
speed = transform.rotation * speed;
characterController.Move( speed * Time.deltaTime );
}
}
Maybe you will find something here? :).