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
0
Question by InfamousStudios · Feb 04, 2013 at 04:29 PM · guitextguitextscroll

Scrolling Text

How do I make a line of GUI Text scroll, repeating continuously, to the left of the screen? I prefer to use Javascript, and I tried a < marquee> tag. This is HTML, but when I format it to fit Javascript, It does not work correctly. Any help will be much appreciated!

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 Loius · Feb 04, 2013 at 05:56 PM 0
Share

Unity doesn't use Javascript, it uses Unityscript, which is more program$$anonymous$$g-language and less webpage-speak. They call it Javascript to make it sound more familiar - it has some similarities, but you can't just take a .js webpage and stick it in Unity. :(

I'm pretty sure a marquee GUI element is a non-trivial concept; you'd probably have to alter the displayed string itself to get it to scroll, or use some trickery to write an image over the top of the text as you scroll the element itself.

1 Reply

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

Answer by robertbu · Feb 04, 2013 at 07:25 PM

Here is a script that scrolls a GUI label. It does as @Loius suggested by altering the display string (i.e. it scrolls by characters not pixels). Attach it to an empty game object and set the string, time, and rect. Note that the rectangle needs to be larger than is needed for the string to display on the screen if you want to avoid word clipping. I think you can also turn off the clipping by using a GUI style and setting the clipping property.

 #pragma strict
 var charactersPerSecond : float = 8.0;
 var text : String = "Here is some text to scroll";
 var rect : Rect;
 
 private var textUsing : String;
 private var scrollBasis : String;
 private var scrollText : String;
 
 private var currChar : int = 0;
 private var timer : float = 0.0;
 
 function Start () {
     NewText();
 }
 
 function Update () {
     if (textUsing != text)
         NewText();
 
     var secondsPerCharacter : float = 1.0 / charactersPerSecond;
     if (timer > secondsPerCharacter) {
       var iT : int = Mathf.FloorToInt(timer / secondsPerCharacter);
       currChar = (currChar + iT) % textUsing.Length;
       timer -= iT * secondsPerCharacter;
       scrollText = scrollBasis.Substring(currChar, textUsing.Length);    
     }
     timer += Time.deltaTime;
 }
 
 function OnGUI() {
 GUI.Label(rect, scrollText);
 }
 
 function NewText() {
     textUsing = text;
     scrollBasis = textUsing+textUsing;
     currChar = 0;
     scrollText = scrollBasis.Substring(currChar, textUsing.Length);
     timer = 0.0;
 }
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 AevinGames · Feb 06, 2016 at 06:42 PM 0
Share

Can you translate into c#??? Only know basic Javascript...

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

11 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

Related Questions

GUIText not working properly with a timer. 1 Answer

How to save and load text in a GUI TextArea 1 Answer

Why this Error when trying to add a score using the new GUI ? 0 Answers

Restrict characters in GUI.TextField 4 Answers

How do I Script GUI Text Objects? 1 Answer


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