简体   繁体   English

通过 Unity 中的其他脚本缩放或缩小相机

[英]Zoom or dezoom camera through an other script in Unity

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:我开始使用 OnMouseOver 函数在我的对象 Ball 上编写我的第一部分代码,但我不知道如何通过我的 Class Ball(或其他类)访问 mainCamera 他是我的第一部分代码:

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谢谢您的帮助

You can access the main camera on your script by the static class "Camera", and change the property "orthographicSize" to do it.您可以通过静态类“Camera”访问脚本上的主相机,并更改属性“orthographicSize”来执行此操作。

EX:前任:

Camera.main.orthographicSize = 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM