Zoom or dezoom camera through an other script in Unity

Viewed 28

Good morning everybody.

I'm trying to create function that allows to zoom camera. Here's my goal: When I keep mouse down and I move cursor away from origin click, the dezoom camera appear and when I approach cursor from click origin, the zoom camera appear. I begin to write my first part code on my object Ball by using the OnMouseOver function but I don't know how I can access to mainCamera through my Class Ball (or an other class) He's my first part code:

private void OnMouseOver()
    {
        if (!GameManager.Instance.IsPlaying) return;

        if (!m_IsFlying && !m_BallLocked && Input.GetMouseButtonDown(0))
        {
            m_BallLocked = true;
        }
        if (!m_IsFlying && m_BallLocked && Input.GetMouseButtonUp(0))
        {
            m_BallLocked = false;
        }
    }

Thank you for your help

1 Answers

You can access the main camera on your script by the static class "Camera", and change the property "orthographicSize" to do it.

EX:

Camera.main.orthographicSize = 1;
Related