需要帮助在 Unity 3D 中实现移动输入

Posted

技术标签:

【中文标题】需要帮助在 Unity 3D 中实现移动输入【英文标题】:Need help to implement mobile inputs in Unity 3D 【发布时间】:2021-11-04 00:56:27 【问题描述】:

我使用 Unity 2D 游戏套件设计了一款 2D 游戏。我的唯一目的是在 android 设备上发布它们。但不幸的是,它的输入不适用于触摸屏。我想使用虚拟操纵杆移动玩家。有人可以帮我编辑这个 C# 脚本吗?

public InputButton Pause = new InputButton(KeyCode.Escape, XboxControllerButtons.Menu);
    public InputButton Interact = new InputButton(KeyCode.E, XboxControllerButtons.Y);
    public InputButton MeleeAttack = new InputButton(KeyCode.K, XboxControllerButtons.X);
    public InputButton RangedAttack = new InputButton(KeyCode.O, XboxControllerButtons.B);
    public InputButton Jump = new InputButton(KeyCode.Space, XboxControllerButtons.A);
    public InputAxis Horizontal = new InputAxis(KeyCode.D, KeyCode.A, XboxControllerAxes.LeftstickHorizontal);
    public InputAxis Vertical = new InputAxis(KeyCode.W, KeyCode.S, XboxControllerAxes.LeftstickVertical);
    [HideInInspector]
    public DataSettings dataSettings;

【问题讨论】:

this 对您的问题有帮助吗? 没有。我试过了.. 【参考方案1】:

您可以从资源商店下载资源来进行触摸控制。

您也可以自己编程。您可以从Input.Touches 获取有关用户如何触摸屏幕的所有信息 要制作虚拟操纵杆,您需要将触摸的当前位置与其在其 Phase 为 TouchPhase.Began 的帧上的位置进行比较

【讨论】:

以上是关于需要帮助在 Unity 3D 中实现移动输入的主要内容,如果未能解决你的问题,请参考以下文章

虚拟仿真Unity3D中实现InputField组件表格Tab或者Enter换行实现

虚拟仿真Unity3D中实现UI跟随3D模型旋转移动UI一直面朝屏幕

虚拟仿真Unity3D中实现UI跟随3D模型旋转移动UI一直面朝屏幕

如何在Unity3d开发中实现文字的渐隐效果

在Unity3D中实现高效的战斗飘字

Unity3D编辑器扩展Unity3D中实现UI界面控制,UI界面的显示和隐藏实现