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.
 
 
 
 

32 lines
1.1 KiB

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;
[SerializeField] private float m_OffsetX = 0f;
[SerializeField] private float m_OffsetY = 2.0f;
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 - m_OffsetX) * Time.deltaTime : 0),
(m_FollowY ? (m_FollowStrength + Player.transform.position.y - m_Camera.transform.position.y - m_OffsetY) * Time.deltaTime : 0),
0);
}
}
}