Advertisement
lemansky

Untitled

Apr 4th, 2021
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraFollow : MonoBehaviour
  6. {
  7.     public GameObject player;
  8.     public Vector3 offset;
  9.     public float rotateSpeed = 5.0f;
  10.  
  11.     void Start()
  12.     {
  13.         player = GameObject.Find("Player");
  14.         offset = transform.position - player.transform.position;
  15.     }
  16.  
  17.     void LateUpdate()
  18.     {
  19.         if (Input.GetMouseButton(1))
  20.         {
  21.             Quaternion angle = Quaternion.AngleAxis(Input.GetAxisRaw("Mouse X") * rotateSpeed, Vector3.up);
  22.             offset = angle * offset;
  23.         }
  24.  
  25.         transform.position = player.transform.position + offset;
  26.  
  27.         transform.LookAt(player.transform);
  28.        
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement