c# - 鼠标滚轮输入无法统一识别

标签 c# input unity3d scrollwheel

试图让缩放相机脚本工作,但没有成功。我的脚本的其他部分运行良好,除了这一部分,我认为它与鼠标滚轮有关。

void LateUpdate()
{
    if (!EventSystem.current.IsPointerOverGameObject())
    {     
        if(Input.GetAxis("Mouse ScrollWheel")<0)
        {
            CameraZoom();
        }
    }
}

public void CameraZoom()
{
    if (!EventSystem.current.IsPointerOverGameObject())
    {
        distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * zoomFactor, distanceMin, distanceMax);
        RaycastHit hit;

        if (Physics.Linecast(target.position, transform.position, out hit))
        {
            distance -= hit.distance;
        }
    }
}

我只是希望它在我移动鼠标滚轮时缩放,但我需要它是一个公共(public)空隙,以便我可以从其他脚本访问它,主要是轻松触摸。

最佳答案

尝试将此代码放在 Update() 而不是 LateUpdate() 中。

void Update()
{
if (!EventSystem.current.IsPointerOverGameObject())
    {     
    if(Input.GetAxis("Mouse ScrollWheel")<0)
        {
            CameraZoom();
        }
    }
}

关于c# - 鼠标滚轮输入无法统一识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35846335/

相关文章:

c# - 从 .DLL 获取位图,转换为 byte[] 和图像

c# - 如何在TreeView中选择某个子节点,C#

python - 作为对象输入 python 3

javascript - 始终检查输入中的值

c# - 编译器错误: Unexpected symbol '}'

c# - 顺利移动我的游戏对象的最佳方式?

c# - 捕获的 .NET 异常意外为空

c# - 从字符串中获取特定的单词c#

bash - 在后台处理用户输入

c# - OnTriggerEnter() 在开始时被调用