28 lines
691 B
C#
28 lines
691 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CameraController : MonoBehaviour
|
|
{
|
|
|
|
[SerializeField] private Transform target;
|
|
[SerializeField] private Vector2 minMaxXY;
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (target == null)
|
|
{
|
|
Debug.LogWarning("摄像机没有主角对象引用");
|
|
return;
|
|
}
|
|
Vector3 targetPosition = target.position;
|
|
targetPosition.z = -10;
|
|
|
|
targetPosition.x = Mathf.Clamp(targetPosition.x, -minMaxXY.x, minMaxXY.x);
|
|
targetPosition.y = Mathf.Clamp(targetPosition.y, -minMaxXY.y, minMaxXY.y);
|
|
|
|
transform.position = targetPosition;
|
|
}
|
|
|
|
}
|