카메라 설정 변경
45도 y:18 z:-18 로 설정 z축만 follow하는 컨트롤러도 사용해봤으나 별로여서 코드만 남겨둠.
This commit is contained in:
49
Assets/Scripts/SimpleCameraZFollow.cs
Normal file
49
Assets/Scripts/SimpleCameraZFollow.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SimpleCameraZFollow : MonoBehaviour
|
||||
{
|
||||
[Header("Camera Settings")]
|
||||
[SerializeField] private float fixedXPosition = 0f;
|
||||
[SerializeField] private float fixedYPosition = 10f;
|
||||
[SerializeField] private float zOffset = -10f;
|
||||
[SerializeField] private float smoothSpeed = 5f;
|
||||
[SerializeField] private bool lockRotation = true;
|
||||
|
||||
private Transform target;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
FindPlayerTarget();
|
||||
}
|
||||
|
||||
private void FindPlayerTarget()
|
||||
{
|
||||
var players = FindObjectsByType<NetworkPlayerController>(FindObjectsSortMode.None);
|
||||
foreach (var player in players)
|
||||
{
|
||||
if (player.IsOwner)
|
||||
{
|
||||
target = player.transform;
|
||||
Debug.Log($"<color=green>[Camera] Target found: {player.name}</color>");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Invoke(nameof(FindPlayerTarget), 0.5f);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (target == null) return;
|
||||
|
||||
Vector3 targetPos = target.position;
|
||||
Vector3 desiredPosition = new Vector3(fixedXPosition, fixedYPosition, targetPos.z + zOffset);
|
||||
|
||||
transform.position = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed * Time.deltaTime);
|
||||
|
||||
if (!lockRotation)
|
||||
{
|
||||
transform.LookAt(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user