【问题标题】:How do I detect when a user clicks on my slider rather than just sliding in unity?如何检测用户何时单击我的滑块而不是统一滑动?
【发布时间】:2019-10-15 18:53:33
【问题描述】:

我在 Unity 中使用 Slider 控件从用户那里获取反馈。我知道如何检测用户在滑动箭头时何时更改滑块的值。

但是,如果用户不想移动滑块,我似乎无法找到一种方法来检测用户是否只是单击滑块的当前位置。我想避免添加其他视觉控件。

有什么方法可以检测用户何时点击滑块?

【问题讨论】:

    标签: c# unity3d slider unity5


    【解决方案1】:

    您需要使用事件触发器并选择指针单击并结束拖动。 我遇到了同样的问题,我就这样解决了。

    【讨论】:

      【解决方案2】:

      来自https://docs.unity3d.com/ScriptReference/UI.Selectable.OnPointerDown.html

      从那里您可以检查滑块的值是否已更改,以查看用户是否单击了当前位置。

      using UnityEngine;
      using System.Collections;
      using UnityEngine.UI;
      using UnityEngine.EventSystems;// Required when using Event data.
      
      public class ExampleClass : MonoBehaviour, IPointerDownHandler// required interface when using the OnPointerDown method.
      {
          //Do this when the mouse is clicked over the selectable object this script is attached to.
          public void OnPointerDown (PointerEventData eventData) 
          {
              Debug.Log (this.gameObject.name + " Was Clicked.");
          }
      }
      

      【讨论】:

      • 这就是 Op 正在寻找的。​​span>
      • 我修好了。问题不在代码中,我只需要添加一个pointerClick事件触发器。
      猜你喜欢
      • 2012-08-18
      • 1970-01-01
      • 2018-06-03
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      • 2016-10-03
      • 2023-04-01
      • 2016-12-29
      相关资源
      最近更新 更多