Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UnityEngine
- [AddComponentMenu("Interface/Centre Ship Camera")]
- class CentreShipCamera(MonoBehaviour):
- [SerializeField] m_target as Transform
- [SerializeField] m_zoomAxis = "Mouse ScrollWheel"
- [SerializeField] m_zoomSpeed = 1f
- [SerializeField] m_minZoom = 4f
- [SerializeField] m_maxZoom = 100f
- m_offset as Vector3
- m_normalizedOffset as Vector3
- m_fieldOfView as single
- def Start():
- m_offset = transform.position - m_target.position
- m_normalizedOffset = m_offset.normalized
- m_fieldOfView = (camera.orthographicSize if camera.isOrthoGraphic else camera.fieldOfView)
- def LateUpdate():
- m_fieldOfView *= 1f - Input.GetAxis(m_zoomAxis)*m_zoomSpeed
- m_fieldOfView = Mathf.Clamp(m_fieldOfView, m_minZoom, m_maxZoom)
- camera.orthographicSize = m_fieldOfView;
- camera.fieldOfView = m_fieldOfView
- transform.position = m_target.position + m_offset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement