Global Game Jam 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
950 B

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);
}
}
}