Unity Roll-a-ball 学习笔记 2

B站Unity官方放出了Roll a ball新版教学视频,中文字幕。有一些和之前版本不一样的变动,记录一下遇到的问题。

InputSystem

原输入系统 UnityEngine.Input 在多设备和多平台输入处理时显得力不从心且不够优雅,甚至连游戏中热插拔手柄这种操作都显得十分臃肿和复杂。Unity Tec 从 2016 年起开始逐步开发新一代输入系统 UnityEngine.InputSystem 。

https://www.jianshu.com/p/a14ac96e6384

感觉InputSystem是个比较值得深入研究的东西,后续慢慢研究叭。

首先需要添加InputSystem包,windows -> Package Manager 搜索InputSystem添加并重启。

选中Player,Add Component -> Player Input -> Create Actions创建input actions。

选中Player,Add Component -> New Script

在cs端的void OnMove(InputValue movementValue)方法内可以收到用户操作的移动信息。

但是使用过程中遇到问题,报Unity type or namespace name ‘InputSystem’ does not exist in the namespace ‘UnityEngine’。解决办法是在Unity端Preferences -> External Tools,External Script Editor选择Visual Studio,在下方勾选Registry packages,并点击Regenerate project files。

Unity type or namespace name ‘InputSystem’ does not exist in the namespace ‘UnityEngine’

Time.deltaTime

The interval in seconds from the last frame to the current one (Read Only)

这帧距离上一帧的秒数。所以在计算pick up应该旋转多少角度时,应该用速度乘以此秒数,这样就不会因为卡阵而造成旋转卡顿。

    transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);

在编辑器中切换某个object的拖拽方向

在旋转了pick up之后,发现无法在全局坐标系下拖拽,只能在旋转后的坐标系下拖拽。google没搜索到结果,于是瞎点,发现左上方第二组有个按钮,点击可以在Global和Local之间切换。点击切换到Global即可在全局坐标系下拖拽。

发表评论

电子邮件地址不会被公开。 必填项已用*标注