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

42 lines
1.3 KiB
C#

using Cinemachine;
using UnityEngine;
public class TowerCam : MonoBehaviour
{
[SerializeField] private GameObject m_gameObject;
public GameObject newTarget;
private void Start()
{
if (m_gameObject == null)
m_gameObject = this.gameObject;
}
public void ChangeToTarget(GameObject target)
{
float originalOffset = m_gameObject.GetComponent<CinemachineCameraOffset>().m_Offset.z;
if (target != null)
{
newTarget = target;
m_gameObject.GetComponent<CinemachineFreeLook>().m_LookAt = target.transform;
m_gameObject.GetComponent<CinemachineFreeLook>().m_Follow = target.transform;
m_gameObject.GetComponent<CinemachineFreeLook>().m_Priority = 11;
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;
m_gameObject.GetComponent<CinemachineCameraOffset>().m_Offset.z = 0;
}
else
{
m_gameObject.GetComponent<CinemachineFreeLook>().m_Priority = 9;
m_gameObject.GetComponent<CinemachineCameraOffset>().m_Offset.z = originalOffset;
}
}
}