Added Animations. Changed inspector view for navpoints. A lot of fixes. Changed project structure.
This commit is contained in:
61
Assets/Scripts/CameraScripts/CameraHandler.cs
Normal file
61
Assets/Scripts/CameraScripts/CameraHandler.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CameraScripts
|
||||
{
|
||||
public class CameraHandler : MonoBehaviour
|
||||
{
|
||||
public Transform targetTransform;
|
||||
public Transform cameraTransform;
|
||||
public Transform cameraPivotTransform;
|
||||
private Transform _myTransform;
|
||||
private Vector3 _cameraTransformPosition;
|
||||
private LayerMask ignoreLayers = ~(1 << 8 | 1 << 9 | 1 << 10);
|
||||
|
||||
public static CameraHandler Singleton;
|
||||
|
||||
public const float LookSpeed = 0.1f;
|
||||
public const float FollowSpeed = 0.1f;
|
||||
public const float PivotSpeed = 0.03f;
|
||||
|
||||
private float _defaultPosition;
|
||||
private float _lookAngle;
|
||||
private float _pivotAngle;
|
||||
|
||||
public float minimumPivot = -35;
|
||||
public float maximumPivot = 35;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Application.targetFrameRate = 60;
|
||||
Singleton = this;
|
||||
_myTransform = transform;
|
||||
_defaultPosition = _myTransform.localPosition.z;
|
||||
}
|
||||
|
||||
public void TargetPosition(float delta)
|
||||
{
|
||||
var toTargetPosition = Vector3.Lerp(_myTransform.position, targetTransform.position, delta /FollowSpeed);
|
||||
_myTransform.position = toTargetPosition;
|
||||
}
|
||||
|
||||
public void HandleCameraRotation(float delta, float mouseX, float mouseY)
|
||||
{
|
||||
_lookAngle += (mouseX * LookSpeed) / delta;
|
||||
_pivotAngle -= (mouseY * PivotSpeed) / delta;
|
||||
_pivotAngle = Mathf.Clamp(_pivotAngle, minimumPivot, maximumPivot);
|
||||
|
||||
var rotation = Vector3.zero;
|
||||
rotation.y = _lookAngle;
|
||||
var targetRotation = Quaternion.Euler(rotation);
|
||||
_myTransform.rotation = targetRotation;
|
||||
|
||||
rotation = Vector3.zero;
|
||||
rotation.x = _pivotAngle;
|
||||
targetRotation = Quaternion.Euler(rotation);
|
||||
cameraPivotTransform.localRotation = targetRotation;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user