Для примера, использую банальный GUI.BeginScrollView и GUI.Button, нужно как то сбросить событие нажатия кнопки, если началась прокрутка.
Синтаксис:
Используется csharp
private Vector2 scrollPosition;
private Vector2 touchDelta;
public Rect rect;
private void Update(){
touchDelta = IsMoved(rect);
if(touchDelta.y != 0)scrollPosition.y += touchDelta.y;
}
public Vector2 IsMoved(Rect _rect){
foreach(Touch touch in Input.touches) {
Vector2 touchPosition = touch.position;
touchPosition.y = Screen.height - touchPosition.y;
if(_rect.Contains(touchPosition))
if(touch.phase == TouchPhase.Moved)return touch.deltaPosition * GetTouchDeltaTime(touch);
}
return Vector2.zero;
}
private float GetTouchDeltaTime(Touch _touch){
if(_touch.deltaTime > 0)return Time.deltaTime/_touch.deltaTime;
else return 1;
}//GetTouchDeltaTime
void OnGUI() {
scrollPosition = GUI.BeginScrollView(new Rect (0, 0, 100, 100), scrollPosition, new Rect (0, 0, 100, 100));
if(GUI.Button (new Rect (0, 0, 20, 10), "")){
}
GUI.EndScrollView ();
}
private Vector2 touchDelta;
public Rect rect;
private void Update(){
touchDelta = IsMoved(rect);
if(touchDelta.y != 0)scrollPosition.y += touchDelta.y;
}
public Vector2 IsMoved(Rect _rect){
foreach(Touch touch in Input.touches) {
Vector2 touchPosition = touch.position;
touchPosition.y = Screen.height - touchPosition.y;
if(_rect.Contains(touchPosition))
if(touch.phase == TouchPhase.Moved)return touch.deltaPosition * GetTouchDeltaTime(touch);
}
return Vector2.zero;
}
private float GetTouchDeltaTime(Touch _touch){
if(_touch.deltaTime > 0)return Time.deltaTime/_touch.deltaTime;
else return 1;
}//GetTouchDeltaTime
void OnGUI() {
scrollPosition = GUI.BeginScrollView(new Rect (0, 0, 100, 100), scrollPosition, new Rect (0, 0, 100, 100));
if(GUI.Button (new Rect (0, 0, 20, 10), "")){
}
GUI.EndScrollView ();
}