Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by TimNick151297 · Aug 30, 2016 at 02:20 PM · uitextscrollingmarquee

Marquee/scrolling text with Unity 4.6 UI

Hey there,

I'd like to create a marquee/scrolling effect just like in html with the UI.Text-Component. The text should scroll to the boundaries of the rect transform and then repeat scrolling from the other side. I really don't know where to start. There are a few existing solutions for scrolling text, but they use GUI or they scroll to the end of the screen - which is not the solution I want.

Any help is appreciated! Thank you :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Sardonic · Feb 06, 2017 at 01:44 AM

Alright @TimNick151297, so, this isn't award winning™ scripting by anybody's standard, but I ran into this situation recently, and this is what I did:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class HorizontalScroll : MonoBehaviour
 {
     public ScrollRect myScrollRect;
     public float speed;
     public float refreshdelay;
 
     void Update()
     {
     if (myScrollRect.horizontalNormalizedPosition < 1)
     {
         myScrollRect.horizontalNormalizedPosition = myScrollRect.horizontalNormalizedPosition + speed;
     }
         if (myScrollRect.horizontalNormalizedPosition > 1)
         {
             StartCoroutine(refresh());
         }
     }
     IEnumerator refresh()
     {
         yield return new WaitForSeconds(refreshdelay);
         myScrollRect.horizontalNormalizedPosition = 0.0f;
         StopAllCoroutines();
     }
 }

Variables are: Speed - something around 0.005 Refreshdelay - in seconds, I used 2

Other requirements: Scroll Rect, throw away scrollbars. Put a 'Text' on the content, and make sure it's showing up properly with the viewport set to be the proper viewing area in the scrollview, and the content expanding to the right.

Put a Content Size Fitter on the text, set to preferred size on the horizontal axis.

Hopefully this can help anyone else in this situation as well, and maybe somebody can come up with something more bulletproof.

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

Answer by shawonRokerz · Jul 04, 2021 at 08:34 AM

Hello Anyone who is struggling with marquee text issue can follow the following code

 public string message;
 public float scrollSpeed = 10;

 public RectTransform panelItem;
 public Text textItem;

 float panelItemWidth;

 void Start()
 {
     panelItemWidth = panelItem.rect.width;
     textItem.text = message;
 }

 void OnGUI()
 {
     textItem.transform.position -= new Vector3((Time.deltaTime * scrollSpeed), 0, 0);
     if (textItem.gameObject.GetComponent<RectTransform>().transform.localPosition.x <= -(textItem.gameObject.GetComponent<Text>().preferredWidth) )
     {
         textItem.transform.localPosition = new Vector3(panelItemWidth, 0, 0);
     }
 }


Here I have used a parent UI Panel which is holding the text component (UI Text) for marquee. I also use a Rect Mask 2D in UI Panel and for the UI Text I set Horizontal Overflow to Overflow as to make it workable. Hope this will help other. Thanks

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 unCrazedLuke · Dec 22, 2021 at 04:42 PM 0
Share

Yeah, no. This doesn't work. Been at this for about 20 or so hours and can't get it working what so ever. It either doesn't stop scrolling OR it changes the XYZ coords to be thousands of numbers away.

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

6 People are following this question.

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

Related Questions

How to prevent scroll rect's content from moving after it reached its borders? 0 Answers

UI Canvas Anchor points are stuck in the bottom left corner and disabled when in overlay mode. 1 Answer

How To Load TTF Font From External File 0 Answers

How to make Textmesh Pro effects on only one text object? 1 Answer

OnGUI behind UI? 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