19 lines
664 B
C#
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;
|
|
}
|
|
}
|