using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraMovement : MonoBehaviour { GameObject player; [Header("Movement Shifting")] [SerializeField] float xOffset; [SerializeField] float yOffset; [SerializeField] float smoothing; [Header("Locking")] [SerializeField] bool xLocked; [SerializeField] bool yLocked; void Awake() { FindPlayer(); } // Update is called once per frame void Update() { if (player != null) { float xPos = transform.position.x; float yPos = transform.position.y; if (!xLocked) { xPos = Mathf.Lerp(transform.position.x, player.transform.position.x + xOffset, Time.deltaTime * smoothing); } if (!yLocked) { yPos = Mathf.Lerp(transform.position.y, player.transform.position.y + yOffset, Time.deltaTime * smoothing); } this.gameObject.transform.position = new Vector3 (xPos, yPos, transform.position.z); } } public void FindPlayer() { player = GameObject.FindGameObjectWithTag("Player"); } }