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

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CameraFollower : MonoBehaviour
  5. {
  6. public GameObject Player;
  7. [SerializeField] private float m_FollowStrength = 3f;
  8. [SerializeField] private bool m_FollowX = true;
  9. [SerializeField] private bool m_FollowY = false;
  10. private Camera m_Camera;
  11. private void Start()
  12. {
  13. m_Camera = GetComponent<Camera>();
  14. }
  15. private void Update()
  16. {
  17. if(Mathf.Abs(Player.transform.position.x - m_Camera.transform.position.x) > m_FollowStrength)
  18. {
  19. m_Camera.transform.Translate(
  20. m_FollowX ? (m_FollowStrength + Player.transform.position.x - m_Camera.transform.position.x) * Time.deltaTime : 0,
  21. m_FollowY ? (m_FollowStrength + Player.transform.position.y - m_Camera.transform.position.y) * Time.deltaTime : 0,
  22. 0);
  23. }
  24. }
  25. }