using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CameraFollower : MonoBehaviour
|
|
{
|
|
public GameObject Player;
|
|
|
|
[SerializeField] private float m_FollowStrength = 3f;
|
|
[SerializeField] private bool m_FollowX = true;
|
|
[SerializeField] private bool m_FollowY = false;
|
|
|
|
private Camera m_Camera;
|
|
|
|
private void Start()
|
|
{
|
|
m_Camera = GetComponent<Camera>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(Mathf.Abs(Player.transform.position.x - m_Camera.transform.position.x) > m_FollowStrength)
|
|
{
|
|
m_Camera.transform.Translate(
|
|
m_FollowX ? (m_FollowStrength + Player.transform.position.x - m_Camera.transform.position.x) * Time.deltaTime : 0,
|
|
m_FollowY ? (m_FollowStrength + Player.transform.position.y - m_Camera.transform.position.y) * Time.deltaTime : 0,
|
|
0);
|
|
}
|
|
}
|
|
}
|