我已经有了这个脚本。
using UnityEngine;
using System.Collections;
public class scrollView: MonoBehaviour {
Vector2 scrollPosition;
Touch touch;
// The string to display inside the scrollview. 2 buttons below add & clear this string.
string longString = "This is a long-ish string";
void OnGUI() {
scrollPosition = GUI.BeginScrollView(new Rect(110, 50, 130, 150), scrollPosition, new Rect(110, 50, 130, 560), GUIStyle.none, GUIStyle.none);
for (int i = 0; i < 20; i++) {
GUI.Box(new Rect(110, 50 + i * 28, 100, 25), "xxxx_" + i);
}
GUI.EndScrollView();
}
void Update() {
if (Input.touchCount > 0) {
touch = Input.touches[0];
if (touch.phase == TouchPhase.Moved) {
scrollPosition.y += touch.deltaPosition.y;
}
}
}
}
我将此脚本用于项目中的滚动屏幕。它运作良好但需要一些优化。我无法找到如何做到这一点。当我快速滑动手指时,我希望它快速滚动,当我慢慢滑动手指时,我希望它能够慢慢滚动。我怎样才能做到这一点?非常感谢你的回答!