【发布时间】:2019-10-15 18:53:33
【问题描述】:
我在 Unity 中使用 Slider 控件从用户那里获取反馈。我知道如何检测用户在滑动箭头时何时更改滑块的值。
但是,如果用户不想移动滑块,我似乎无法找到一种方法来检测用户是否只是单击滑块的当前位置。我想避免添加其他视觉控件。
有什么方法可以检测用户何时点击滑块?
【问题讨论】:
我在 Unity 中使用 Slider 控件从用户那里获取反馈。我知道如何检测用户在滑动箭头时何时更改滑块的值。
但是,如果用户不想移动滑块,我似乎无法找到一种方法来检测用户是否只是单击滑块的当前位置。我想避免添加其他视觉控件。
有什么方法可以检测用户何时点击滑块?
【问题讨论】:
来自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.");
}
}
【讨论】: