Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @script RequireComponent(CharacterController)
- @script AddComponentMenu ("Camera-Control/Mouse Look")
- enum RotationAxe { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
- var axes = RotationAxe.MouseXAndY;
- var sensitivityX : float = 2;
- var sensitivityY : float = 2;
- var minimumX : float = -360;
- var maximumX : float = 360;
- var minimumY : float = -60;
- var maximumY : float = 60;
- var rotationX : float = 0;
- var rotationY : float = 0;
- private var originalRotation : Quaternion;
- //Tastaturbewegung
- private var controller : CharacterController;
- private var dir : Vector3 = Vector3.zero;
- var speed : float = 6;
- var gravity : float = 9.81;
- var rennen :float = 2;
- var rotatation : Transform;
- function Awake()
- {
- controller = GetComponent(CharacterController);
- }
- function Update () {
- if (axes == RotationAxe.MouseXAndY && Input.GetKey(KeyCode.Mouse1)) {
- rotationX += Input.GetAxis("Mouse X") * sensitivityX;
- rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
- rotationX = ClampAngle (rotationX, minimumX, maximumX);
- rotationY = ClampAngle (rotationY, minimumY, maximumY);
- var xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
- var yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
- transform.localRotation = originalRotation * xQuaternion * yQuaternion;
- }
- else if (axes == RotationAxe.MouseX && Input.GetKey(KeyCode.Mouse1)) {
- rotationX += Input.GetAxis("Mouse X") * sensitivityX;
- rotationX = ClampAngle (rotationX, minimumX, maximumX);
- xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
- transform.localRotation = originalRotation * xQuaternion;
- }
- // Tastaturbewegung
- dir.x = 0;
- dir.z = 0;
- if(controller.isGrounded) //auf dem Boden
- {
- dir.y = -1;
- if(Input.GetKey("e"))
- {
- dir.x = 1 * speed;
- }
- if(Input.GetKey("q"))
- {
- dir.x = -1 * speed;
- }
- if(Input.GetKey("w"))
- {
- dir.z = 1 * speed;
- }
- if(Input.GetKey("s"))
- {
- dir.z = -1 * speed;
- }
- if(Input.GetKey("a"))
- {
- transform.Rotate(0, -100 * Time.deltaTime, 0);
- controller.SimpleMove(transform.TransformDirection(dir));
- }
- if(Input.GetKey("d"))
- {
- transform.Rotate(0, 100 * Time.deltaTime, 0);
- controller.SimpleMove(transform.TransformDirection(dir));
- }
- }
- else //in der Luft
- {
- dir.y -= gravity * Time.deltaTime;
- }
- controller.Move(dir * Time.deltaTime);
- }
- function Start () {
- if (rigidbody)
- rigidbody.freezeRotation = true;
- originalRotation = transform.localRotation;
- }
- static function ClampAngle (angle : float, min : float, max : float) : float {
- if (angle < -360.0)
- angle += 360.0;
- if (angle > 360.0)
- angle -= 360.0;
- return Mathf.Clamp (angle, min, max);
- }
Add Comment
Please, Sign In to add comment