Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CameraController : MonoBehaviour
- {
- public Transform lookAt;
- public Transform lookAtDead;
- public Transform camTransform;
- private Camera cam;
- public float distance = 10.0f;
- public float currentX = 0.0f;
- public float currentY = 0.0f;
- public float maxDistance;
- public float minDistance;
- public float maxY;
- public float minY;
- //private float sensivityX = 4.0f;
- //private float sensivityY = 1.0f;
- private void Start()
- {
- camTransform = transform;
- cam = Camera.main;
- }
- private void Update()
- {
- if (lookAt != null)
- {
- currentX += Input.GetAxis("Mouse X");
- currentY -= Input.GetAxis("Mouse Y");
- distance += Input.GetAxis("Mouse ScrollWheel");
- if (currentY < minY)
- {
- currentY = minY;
- }
- if (currentY > maxY)
- {
- currentY = maxY;
- }
- if (distance < 2)
- {
- distance = 2;
- }
- if (distance > 12)
- {
- distance = 12;
- }
- }
- }
- private void LateUpdate()
- {
- if ( lookAt != null )
- {
- Vector3 dir = new Vector3(0, 0, -distance);
- Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
- camTransform.position = lookAt.position + rotation * dir;
- camTransform.LookAt(lookAt.position);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement