Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (36 sloc) 1.37 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollowObject : MonoBehaviour {
private GameObject target;
private Vector3 offset;
private float horizontal;
private float vertical;
private float max_y, min_y;
private float rotationSpeed;
private float rotationVelocity;
private float movementSpeed;
//private CameraZoom cameraZoom;
private void Start()
//cameraZoom = GetComponent<CameraZoom>();
private void LateUpdate()
horizontal = InputManager.Get_MouseX * rotationSpeed;
vertical -= InputManager.Get_MouseY * rotationSpeed;
vertical = Mathf.Clamp(vertical, min_y, max_y);
target.transform.Rotate(0, horizontal, 0);
float angleY = Mathf.SmoothDampAngle(this.transform.eulerAngles.y, target.transform.eulerAngles.y, ref rotationVelocity, 0);
this.transform.rotation = Quaternion.Euler(vertical, angleY, 0);
Quaternion targetRotation = target.transform.rotation;
Vector3 newPos = targetRotation * offset;
newPos += new Vector3(target.transform.position.x, target.transform.position.y, target.transform.position.z);
this.transform.position = newPos;
You can’t perform that action at this time.