Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Cam : MonoBehaviour
- {
- [SerializeField] private GameObject TargetObject;
- [Header ("Position")]
- [SerializeField] private float DeltaX;
- [SerializeField] private float DeltaY;
- [SerializeField] private float DeltaZ;
- [Header("Rotation")]
- [SerializeField] private float RotationDeltaX;
- [SerializeField] private float RotationDeltaY;
- [Header("Extra Options")]
- [SerializeField] private bool LockRotation;
- private void SetPosition()
- {
- float CurrentX = TargetObject.transform.position.x + DeltaX;
- float CurrentY = TargetObject.transform.position.y + DeltaY;
- float CurrentZ = TargetObject.transform.position.z - DeltaZ;
- float CurrentRotationX, CurrentRotationY;
- if (LockRotation)
- {
- CurrentRotationX = RotationDeltaX;
- CurrentRotationY = RotationDeltaY;
- }
- else
- {
- CurrentRotationX = TargetObject.transform.rotation.eulerAngles.x + RotationDeltaX;
- CurrentRotationY = TargetObject.transform.rotation.eulerAngles.y + RotationDeltaY;
- }
- transform.position = new Vector3(CurrentX, CurrentY, CurrentZ);
- transform.rotation = Quaternion.Euler(new Vector3(CurrentRotationX, CurrentRotationY, TargetObject.transform.rotation.eulerAngles.z));
- }
- // Start is called before the first frame update
- void Start()
- {
- LockRotation = true;
- }
- // Update is called once per frame
- void Update()
- {
- SetPosition();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement