3DTD/Assets/Scripts/Camera/TowerCam.cs

42 lines
1.3 KiB
C#
Raw Normal View History

2024-04-21 02:09:30 +02:00
using Cinemachine;
using UnityEngine;
public class TowerCam : MonoBehaviour
{
2024-04-21 04:00:56 +02:00
[SerializeField] private GameObject m_gameObject;
public GameObject newTarget;
2024-04-21 02:09:30 +02:00
private void Start()
{
if (m_gameObject == null)
m_gameObject = this.gameObject;
}
public void ChangeToTarget(GameObject target)
{
2024-04-21 04:37:42 +02:00
float originalOffset = m_gameObject.GetComponent<CinemachineCameraOffset>().m_Offset.z;
2024-04-21 02:09:30 +02:00
if (target != null)
{
2024-04-21 04:00:56 +02:00
newTarget = target;
2024-04-21 02:09:30 +02:00
m_gameObject.GetComponent<CinemachineFreeLook>().m_LookAt = target.transform;
m_gameObject.GetComponent<CinemachineFreeLook>().m_Follow = target.transform;
m_gameObject.GetComponent<CinemachineFreeLook>().m_Priority = 11;
2024-04-21 03:22:56 +02:00
2024-04-21 04:00:56 +02:00
m_gameObject.GetComponent<CinemachineFreeLook>().GetRig(0).LookAt = target.transform;
m_gameObject.GetComponent<CinemachineFreeLook>().GetRig(1).LookAt = target.transform;
m_gameObject.GetComponent<CinemachineFreeLook>().GetRig(2).LookAt = target.transform;
2024-04-21 04:37:42 +02:00
m_gameObject.GetComponent<CinemachineCameraOffset>().m_Offset.z = 0;
2024-04-21 02:09:30 +02:00
}
else
{
m_gameObject.GetComponent<CinemachineFreeLook>().m_Priority = 9;
2024-04-21 04:37:42 +02:00
m_gameObject.GetComponent<CinemachineCameraOffset>().m_Offset.z = originalOffset;
2024-04-21 02:09:30 +02:00
}
}
}