Added project
This commit is contained in:
25
Platformer/Assets/Scripts/FollowCamera.cs
Normal file
25
Platformer/Assets/Scripts/FollowCamera.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FollowCamera : MonoBehaviour {
|
||||
|
||||
[Header("Set in Inspector")]
|
||||
public GameObject POI;
|
||||
public float easing = 0.05f;
|
||||
public Vector2 minXY = Vector2.zero;
|
||||
|
||||
private float m_CamZ;
|
||||
|
||||
private void Awake() {
|
||||
m_CamZ = transform.position.z;
|
||||
}
|
||||
|
||||
private void FixedUpdate() {
|
||||
var destination = POI == null ? Vector3.zero : POI.transform.position;
|
||||
destination.x = Mathf.Max(minXY.x, destination.x);
|
||||
destination.y = Mathf.Max(minXY.y, destination.y);
|
||||
destination = Vector3.Lerp(transform.position, destination, easing);
|
||||
destination.z = m_CamZ;
|
||||
transform.position = destination;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user