Code: Select all
private void Update()
{
if (m_mainCamera == null) m_mainCamera = Camera.main;
if (m_mainCamera == null) return;
if (rotate180)
{
if (yAxisOnly)
{
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, (m_mainCamera.transform.rotation.eulerAngles + 180f * Vector3.up).y, transform.rotation.eulerAngles.x);
}
else
{
transform.rotation = Quaternion.LookRotation(-m_mainCamera.transform.forward, m_mainCamera.transform.up);
}
}
else
{
if (yAxisOnly)
{
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, m_mainCamera.transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.x);
}
else
{
transform.rotation = m_mainCamera.transform.rotation;
}
}
}