将UI定位到鼠标位置(使“工具提示"面板跟随光标) [英] Position UI to mouse position (Make Tooltip panel follow cursor)

查看:330
本文介绍了将UI定位到鼠标位置(使“工具提示"面板跟随光标)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使工具提示面板跟随光标

I made a tooltip panel follow the cursor with

void Update () {
    this.transform.position = Input.mousePosition;  
}

在更新功能中.

面板滞后",四分之一秒后移动到光标位置,这很烦人 有更好的方法吗?我可以以某种方式将其粘"到光标上吗? 这是当我从右向左移动鼠标时的外观.

The panel "lags" behind, moving to cursor position after quarter of a second, and its kind of annoying Is there a better way of doing this? Can i somehow "glue" it to the cursor? Here is how it looks when i move mouse from right to left.

当鼠标静止不动时,面板IS位于光标下方,只有在大力移动时面板才会退出.

Panel IS under the cursor when mouse is still, it only trails off when moved vigorously.

推荐答案

这是一个已知的统一性问题.

This is a known issue with unity.

在将鼠标位置绑定到任何gameObject的位置时,我们将面临延迟.这种延迟是由单位输入模块的鼠标位置记录引起的. 参考1

While binding mouse position to any gameObject's position, we face lag. This lag is introduced by unity input module's mouse position recording. Reference1, Reference2.

解决方法::您可以在游戏中创建自己的光标并将其绑定到鼠标位置(在绑定UI面板时).游戏中的自定义光标对象将与面板具有相同的位置,因为这两个对象都将从相同的源获得它们的位置.您将获得一个无滞后的面板. :)

Work Around : You can make your own cursor in game and bind it to mouse position(as you're binding the UI panel). The custom cursor object in game will have the same position as the the panel because both of these objects will derive their position from same source. And you'll get a lag free panel. :)

记住要隐藏默认光标.

这篇关于将UI定位到鼠标位置(使“工具提示"面板跟随光标)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆