2024-11-24 17:46:56 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class CameraController : MonoBehaviour
|
|
|
|
{
|
2024-11-24 18:01:49 +00:00
|
|
|
public Transform cam; // Reference to the camera's Transform
|
|
|
|
public Transform player; // Reference to the player's Transform
|
|
|
|
public float height = 5f; // Height offset of the camera above the player
|
2024-11-24 17:46:56 +00:00
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2024-11-24 18:01:49 +00:00
|
|
|
// Update the camera position to follow the player while maintaining the height
|
|
|
|
Vector3 newCameraPosition = new Vector3(player.position.x, player.position.y + height, player.position.z);
|
|
|
|
cam.position = newCameraPosition;
|
2024-11-24 17:46:56 +00:00
|
|
|
}
|
|
|
|
}
|