Advertisement
sphinx2001

PlayerCamera

Jan 25th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player_Camera : MonoBehaviour {
  6.     public Transform targetPoint;
  7.     public Rigidbody player;
  8.     Transform myTransform;
  9.     Camera cam;
  10.  
  11.    
  12.     private void Start() {
  13.  
  14.         myTransform = transform;
  15.         cam = GetComponent<Camera>();
  16.         Cursor.lockState = CursorLockMode.Locked;
  17.         Cursor.visible = false;
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update () {
  22.  
  23.         if (targetPoint == null)
  24.         return;
  25.  
  26.         myTransform.position = targetPoint.position - player.velocity/20f;
  27.         myTransform.rotation = player.rotation;
  28.         cam.fieldOfView = 60f + player.velocity.magnitude/20f;
  29.         InternalLockUpdate();
  30.     }
  31.  
  32.  
  33.  
  34.     private void InternalLockUpdate()
  35.     {
  36.         if(Input.GetKeyDown(KeyCode.LeftControl))
  37.         {
  38.             Cursor.lockState = CursorLockMode.None;
  39.             Cursor.visible = true;
  40.         }
  41.         else if(Input.GetKeyUp(KeyCode.LeftControl))
  42.         {
  43.             Cursor.lockState = CursorLockMode.Locked;
  44.             Cursor.visible = false;
  45.         }
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement