如何平滑更改正交相机尺寸?

问题描述 投票:0回答:1

我正在尝试在电影机上顺利更改我的正交尺寸。我将其设置为通过鼠标滚轮放大和缩小,但它会立即发生,并且我希望它需要几秒钟才能顺利完成。就像缓慢的放大和缩小一样。我似乎无法让它发挥作用。我正在使用 cinemachine 作为相机并输入动作来捕获当前的变焦。我将其设置为特定数字,因为我希望这些是最大放大和缩小值。

我知道 cinemachine 具有平滑的路径,可以立即更改路径点,我希望也有一个可以立即更改缩放的路径,或者有人知道另一种方法。我想做的就像《最终幻想战术》中的缩放功能,您按下按钮,它会缓慢放大到设定值然后退出,而不是手动不断滚动/按下按钮,最终到达您想要的位置它。

缓慢减小浮点值之类的方法可能会起作用。但这可能需要比我希望的更多的时间。但我欢迎任何关于如何做到这一点的想法。

public class Zoom : MonoBehaviour
{

    public CinemachineVirtualCamera currentCamera;
    
     public void OnZoomIn(InputAction.CallbackContext context)
  {


     if (context.started == true)
    {
      currentCamera.m_Lens.OrthographicSize = 7.0f;
      
    }
  }

  public void OnZoomout(InputAction.CallbackContext context)
  {
     if (context.started == true)
    {
       currentCamera.m_Lens.OrthographicSize = 14.0f;
    }
  }
}

我尝试添加速度值并尝试使用

time.deltatime
,但我做错了或者其他什么,因为它只是把整个相机搞砸了,放大或缩小到很远,但仍然立即发生。

c# unity-game-engine cinemachine
1个回答
0
投票

您需要在某处设置所需的状态(例如属性)并使用

Update
移动到目标大小。

public class Zoom : MonoBehaviour
{

    public CinemachineVirtualCamera currentCamera;
    public bool IsZoomDesired {get; private set; } // Are we zooming in?
   public float Speed = 7.0f; // In zoom units per seconds.

   // Added
   public void Update() 
   {
       var target = IsZoomDesired ? 7.0f : 14.0f;
      currentCamera.m_Lens.OrthographicSize = Mathf.MoveTowards(currentCamera.m_Lens.OrthographicSize, target, Speed * Time.deltaTime);
   }
    
     public void OnZoomIn(InputAction.CallbackContext context)
  {


     if (context.started == true)
    {
       IsZoomDesired  = true;
      
    }
  }

  public void OnZoomout(InputAction.CallbackContext context)
  {
     if (context.started == true)
    {
        IsZoomDesired= false;
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.