【问题标题】:Change controls from mouse to touch in Unity C#在 Unity C# 中将控件从鼠标更改为触摸
【发布时间】:2018-02-24 17:26:32
【问题描述】:

我正在尝试创建一个跟随滑动方向的旋转轮。目前,它适用于鼠标控件,但我未能使此脚本适用于触摸控件。知道该怎么做吗?

脚本:

void Update () 
{
  if (Input.GetMouseButtonDown(0))
  {
      f_difX = 0.0f;
  }
  else if (Input.GetMouseButton(0))
  {
      f_difX = Mathf.Abs(f_lastX - Input.GetAxis ("Mouse X"));

      if (f_lastX < Input.GetAxis ("Mouse X"))
      {
          i_direction = -1;
          transform.Rotate(Vector3.up, -f_difX);
      }

      if (f_lastX > Input.GetAxis ("Mouse X"))
      {
          i_direction = 1;
          transform.Rotate(Vector3.up, f_difX);
      }

      f_lastX = -Input.GetAxis ("Mouse X");
  }
  else 
  {
      if (f_difX > 0.5f) f_difX -= 0.05f;
      if (f_difX < 0.5f) f_difX += 0.05f;

      transform.Rotate(Vector3.up, f_difX * i_direction);
  }
}

谢谢。

【问题讨论】:

    标签: c# unity3d touch mouse swipe


    【解决方案1】:

    看看这个帖子:http://answers.unity3d.com/questions/504707/replace-input-get-axis-horizontal-with-touch-input.html,第一个答案。

    该链接提供了一个代码 sn-p,展示了如何使用计算出的位置增量来替换 Input.GetAxis。

    【讨论】:

    • 有必要简要介绍一下链接中的答案包含的内容 - 特别是因为它不是 stackoverflow 答案,并且可能会在将来的某个时候更改/变得无法访问。
    猜你喜欢
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多