Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by mdunstetter · Dec 11, 2015 at 09:47 AM · uiunity5scrollelastic

Change the "reference position" of an elastic scroll rect

Hello,

I meet a problem with a Unity ScrollRect :

  • I have a looooong item list hidden with a Mask. At the beginning, the local position of the ScrollRect content (my item bar) is Pos X=0.

  • If the user scroll to left to see the hidden items, the movement is Unrestricted

  • If the user scroll to right before the first item (where there is nothing to see), the movement switch to Elastic then the bar reset its position to 0 with a nice elastic movement.

The problem comes on the other side, when the user scroll to left after the last item (where there is nothing to see). The movement switch to Elastic, but I would like the bar to reset its position not to 0, but to the maximum allowed position I set to turn the movement to Elastic (so not reset to the first item but stay on the last item).

I can't find a simple way to do this. The documentation says :

"Use Elastic or Clamped to force the content to remain within the bounds of the Scroll Rect"

But I am not sure about what it's mean and if there is a simple way to control this. How should I deal with this ?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by mdunstetter · Mar 08, 2016 at 03:18 PM

Ok, I didn't find any simple solution to this porblem. By "simple" I mean something that you do easily with the editor and a few lines of code.

So this is the approach I eventually use :

  • No switch to the "Elastic" movement

  • A custom code to make the elastic effect on each side, using a slerp function

       /**
          * Let's say that as long as you are touching the screen, you can scroll 
          * (just slow down the speed when you are out of bounds).
          * This piece of code show what happen when the screen is not touched
          * and we are out of bounds on one of the side.
          */ 
         float vSpeed = 10.0f;
         if (vPosX > _maxPosScrollable)  // Out of bounds
         {
             if( vPosX -_maxPosScrollable <= 0.05 ) // consider the movement finished
             {
                 _scrollableRect.localPosition = new Vector3 (0.1f, 0f, 0f);
                 _scrollRect.velocity = Vector2.zero; // stop the scroll
             }
             else // the elastic effect
             {
                 vSlerp = Vector3.Slerp(vX, vTarget, Time.deltaTime * vSpeed);
                 vPosX = vSlerp.x; // set the current position of the bar with a slerp between the previous position and the wanted position
             }
         }
    
    

Something like this, adapted to your own case (I guess there is a way to do something cleaner but I didn't have more time to spend on this).

If someone need this one day, I can give more precisions.

Comment
Add comment · 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

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

44 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Force a uGUI scrollbar/scrollrect to stay at the bottom when the scrollrect is expanded 0 Answers

Unity Button to switch Bool 1 Answer

How to prevent automatic tmp ugui resizing. 0 Answers

Destroying object multiple times. 0 Answers

Unity (default) Fonts going pink in build (pink squares!!!!) 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