首页 文章

如何在Unity中将幻灯片放大?

提问于
浏览
0

在我的2D Unity项目中,我不得不在主摄像头中使用缩放脚本 . 然而,缩放工作,相机只关注场景的中间 . 但我希望看到场景的其他部分仍然在相机视野之外 . 那么,我应该添加到我的脚本中,以便在缩放时移动场景?

这是我的缩放脚本 . 我把它扔进了主相机 .
enter image description here

此图片是缩放前的实际场景:
enter image description here

而这一个是在缩放之后 . 请注意它直接关注场景的几何中心,并且不允许我移动到场景中的另一个点(向右,向左,向上,向下) .
enter image description here

1 回答

  • 0

    我不知道你是否想要在缩放时拖动或使用鼠标位置作为缩放的中心点 .

    如果是后者,你可以这样做;

    float zoomSpeed = 5f;
    
    void Update()
    {
        if (Input.GetAxis("Mouse ScrollWheel") != 0)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit point; Physics.Raycast(ray, out point, 25); Vector3 Scrolldirection = ray.GetPoint(5);
    
            float step = zoomSpeed * Time.deltaTime;
            mycamera.transform.position = Vector3.MoveTowards(transform.position, Scrolldirection, Input.GetAxis("Mouse ScrollWheel") * step);
        }
    }
    

相关问题