- Home /
Smooth scroll with touch?
like a question upper ,
i still try but just use for mouse not for touch can someoone help me.......
It's not easy. it's possible this could help you
http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html
cheers!
Answer by robertbu · Jan 18, 2013 at 07:54 PM
Here is a starter script. It has limitations and simplifications, but it something you can play with. Attach it to a game object with a collider. It assumes the camera is looking down the Z axis.
using UnityEngine;
using System.Collections;
public class SmoothScroll : MonoBehaviour {
public float fResistanceFactor = 0.98f;
public float fStopThreashold = 0.01f;
Plane planeHit;
Vector3 v3StartPos;
Vector3 v3LastPos;
Vector3 v3Delta;
float fStartTime;
bool bTranslating = false;
void OnMouseDown() {
bTranslating = false;
v3StartPos = GetHitPoint ();
v3LastPos = v3StartPos;
fStartTime = Time.time;
}
void OnMouseDrag() {
Vector3 v3T = GetHitPoint ();
transform.Translate(v3T - v3LastPos);
v3LastPos = v3T;
}
void OnMouseUp() {
v3Delta = GetHitPoint();
v3Delta = (v3Delta - v3StartPos) / (Time.time - fStartTime) * Time.deltaTime;
bTranslating = true;
}
Vector3 GetHitPoint() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float fDist;
if (planeHit.Raycast (ray, out fDist))
return ray.GetPoint (fDist);
else
return Vector3.zero;
}
void Start() {
planeHit = new Plane(Vector3.forward, transform.position);
}
void Update () {
if (bTranslating) {
transform.position += v3Delta;
v3Delta = v3Delta * fResistanceFactor;
if (v3Delta.magnitude < fStopThreashold)
bTranslating = false;
}
}
}
Hello Jan,
how can I adjust this to scroll only on the y-Axis?
Thank you
Ali
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
ListView scrolling with swipe 2 Answers
Vertical scrolbar unity android 0 Answers
GUILayout.BeginScrollView - How to load images downloaded from http ? 1 Answer
Inventory Help. 0 Answers