Advertisement
AndrewRosyaev

PlayerCameraControl

Dec 23rd, 2015
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerCameraControl : MonoBehaviour
  5. {
  6.     public float x;
  7.     public float y;
  8.     public float SpeedRotation;
  9.     public Transform Player;
  10.  
  11.     void Update ()
  12.     {
  13.         x += Input.GetAxis ("Mouse X") * SpeedRotation * Time.deltaTime;
  14.         y += Input.GetAxis ("Mouse Y") * SpeedRotation * Time.deltaTime;
  15.         y = Mathf.Clamp (y, -90, 90);
  16.         Quaternion CameraTarget = Quaternion.Euler (-y, 335, 0);
  17.         Quaternion CharacterTarget = Quaternion.Euler (0, x, 0);
  18.  
  19.         transform.localRotation = CameraTarget;
  20.         Player.localRotation = CharacterTarget;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement