Mini-Games-Game/Assets/Scripts/CameraController.cs
2024-11-24 18:01:49 +00:00

19 lines
664 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
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
// Update is called once per frame
void Update()
{
// 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;
}
}