Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ducanhtuvu · Jan 18, 2013 at 10:39 AM · scrollview

Smooth scroll with touch?

like a question upper ,

i still try but just use for mouse not for touch can someoone help me.......

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Jan 18, 2013 at 12:23 PM 0
Share

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!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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;
         }
     }

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MasterEpik · Sep 22, 2014 at 09:59 AM 0
Share

Hello Jan,

how can I adjust this to scroll only on the y-Axis?

Thank you

Ali

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges