Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class cameracontroler : MonoBehaviour {
- //if nothing click
- public Transform target;
- public float smoothTime = 0.3F;
- private Vector3 velocity = Vector3.zero;
- public float cameraxx = 0f;
- public float camerayy =2f;
- public float camerazz = -4f;
- //CameraOrbit()
- private Vector3 _cameraOffset;
- public Transform PlayerTransform;
- [Range(0.01f, 1.0f)]
- public float SmoothFactor = 0.5f;
- public float RotationsSpeed = 5.0f;
- void Start() {
- _cameraOffset = transform.position - target.position;
- }
- void LateUpdate()
- {
- if (Input.GetMouseButton(1)) {
- cameraorbit();
- }
- else {
- camerasmooth();
- }
- }
- void cameraorbit() {
- Quaternion camTurnAngle =
- Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up);
- _cameraOffset = camTurnAngle * _cameraOffset;
- Vector3 newPos = target.position + _cameraOffset;
- transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);
- transform.LookAt(target);
- }
- void camerasmooth() {
- // Define a target position above and behind the target transform
- Vector3 targetPosition = target.TransformPoint(new Vector3(cameraxx, camerayy, camerazz));
- // Smoothly move the camera towards that target position
- transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
- transform.LookAt(target);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement