-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraController.cs
48 lines (37 loc) · 1.4 KB
/
CameraController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using PlanetTaxi;
using UnityEditorInternal;
using UnityEngine;
namespace PlanetTaxi
{
public class CameraController : MonoBehaviour
{
[Tooltip("Követendő objektum")]
[SerializeField] private TaxiController _taxi;
[Tooltip("Késleltetés")]
[SerializeField] private float _delayTime = 0.25f;
[Tooltip("A kamera pozíciójának minimális Z értéke")]
[SerializeField] private float _minOpen = -10.0f;
[Tooltip("A kamera pozíciójának maximális Z értéke")]
[SerializeField] private float _maxOpen = -25.0f;
private Vector3 _cameraVelocity, _nextPosition, _pastPosition, _pastTaxiPosition;
#if UNITY_EDITOR
private void Start()
{
if (_taxi == null)
{
Debug.Log("Kérlek nézd át a CameraController scriptbe behúzott referenciákat!");
UnityEditor.EditorApplication.isPlaying = false;
}
}
#endif
private void FixedUpdate ()
{
_nextPosition = _taxi.transform.position;
_nextPosition.z = Mathf.Lerp(_minOpen, _maxOpen, _taxi.CurrentSpeed / _taxi.MaxSpeed);
transform.position = Vector3.SmoothDamp(transform.position, _nextPosition, ref _cameraVelocity, _delayTime);
transform.LookAt(_taxi.transform);
}
}
}