Mini-Games-Game/Assets/Scripts/CameraController.cs

19 lines
664 B
C#
Raw Normal View History

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
// 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;
}
}