using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraController : MonoBehaviour{ public GameObject player; // Reference to the transform of the player to follow private float offsetX = 1f; // Distance from the player on the x-axis private float offsetY = 1f; // Distance from the player on the y-axis private float offsetSmoothing = 1f; // Smoothing of the camera's movement private Vector3 targetPosition; // The desired camera position // The y-axis threshold for camera adjustment public float yThreshold = 13f; // Start is called before the first frame update void Start(){ player = GameObject.FindGameObjectWithTag("Player"); } // Update is called once per frame void Update(){ // Set the target position for the camera targetPosition = new Vector3(player.transform.position.x, player.transform.position.y + offsetY, transform.position.z); // Check if the player's y-position exceeds the threshold if (player.transform.position.y > yThreshold){ // Adjust the camera's y-position to follow the player targetPosition.y = player.transform.position.y + offsetY; } // Adjust the camera's x-position based on the player's direction if (player.transform.localScale.x > 0f){ targetPosition.x = player.transform.position.x + offsetX; } else{ targetPosition.x = player.transform.position.x - offsetX; } // Smoothly move the camera towards the target position transform.position = Vector3.Lerp(transform.position, targetPosition, offsetSmoothing * Time.deltaTime); } }