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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by HHameline · May 13, 2011 at 05:55 PM · textscrollcredits

Making Credits Scroll Upwards on Screen

Hello, I'm trying to make very simple credits for my game, and I was thinking about just making a GUIText prefab (creditTextItem), and then read items in from my credits text file, instantiate a new GUIText prefab set its position to off-screen add it to a list of GUIText prefabs, then each update cycle through the list update the position in the y axis a little bit. My code is below.

using UnityEngine; using System.Collections; using System.IO; using System.Collections.Generic;

public class CreditsScript : MonoBehaviour { public GUIText creditTextItem; private List<GUIText> Credits = new List<GUIText>(); private TextReader tr; public string path; private List<string> credits = new List<string>();

 // Use this for initialization
 void Start () 
 {
     // Set the path for the credits.txt file
     path = "Assets/Resources/Credits.txt";

     // Create reader &amp; open file
     tr = new StreamReader(path);

     string temp;
     while((temp = tr.ReadLine()) != null)
     {
         // Read a line of text
         credits.Add(temp);
     }

     // Close the stream
     tr.Close();

     CreateCredits();
 }

 // Update is called once per frame
 void Update () 
 {
     if (Credits.Count &gt; 0)
     {
         for (int i = 0; i &lt; Credits.Count; i++)
         {
             Credits[i].transform.Translate(new Vector3(0f, 1f, 0f));
         }
     }
 }

 void CreateCredits()
 {
     for (int i = 0; i &lt; credits.Count; i++)
     {
         string c = credits[i];
         Instantiate(creditTextItem);
         creditTextItem.transform.position = GameObject.Find("CreditStart").transform.position;
         creditTextItem.text = c;
         Debug.Log(c);
         Credits.Add(creditTextItem);
      }
  }

}

It's reading in the text file properly and updating the list's correctly. But is isn't displaying the items on screen any ideas?

Thanks, Hans

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer Wiki

Answer by DaveA · May 13, 2011 at 05:57 PM

You could try this: http://answers.unity3d.com/questions/44728/how-do-i-make-credits

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
1
Wiki

Answer by kilian277 · May 13, 2011 at 05:57 PM

What is just do is a make a very long cube or plane long in the Y direction, and i just put 3D text infront of the cube or plane.

And then i make the camera go up or down using a animation attached on the camera.

it's simple but it works.

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
Wiki

Answer by HHameline · May 13, 2011 at 06:34 PM

I did some tinkering and it turned out being even easier just using the OnGui() function. Your answer did help me figure it out @ dave so you get the credit :D

public class CreditsScript : MonoBehaviour { public GUISkin creditSkin; public float creditSpeed; private TextReader tr; private string path; private List credits = new List (); private List positionRect = new List ();

 // Use this for initialization
 void Start () 
 {        
     // Set the path for the credits.txt file
     path = "Assets/Resources/Credits.txt";

     // Create reader & open file
     tr = new StreamReader(path);

     string temp;
     int count = 0;
     while((temp = tr.ReadLine()) != null)
     {
         // Read a line of text
         credits.Add(temp);
         positionRect.Add(new Rect(200, 790 + (30 * count), 300, 100));
         Debug.Log(temp);
         count++;
     }

     // Close the stream
     tr.Close();
 }

 // Update is called once per frame
 void OnGUI() 
 {
     GUI.skin = creditSkin;
     for (int i = 0; i < credits.Count; i++)
     {
         GUI.Label(positionRect[i], credits[i], "item");
         Rect tempRect = positionRect[i];
         tempRect.y = tempRect.y - creditSpeed;
         positionRect[i] = tempRect;
     }
 }

}

Thanks for the answers.

Comment
Add comment · Show 4 · 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 TheGeekyDead · Dec 21, 2013 at 09:57 PM 0
Share

Hello, i am trying to implement the same thing, i tried your code but i don't think it works on the free version, or i F'ed it up lol. Can you give me a pointer on what i missed?

Im trying to learn using examples on here i am getting better but this puzzles me ;)

CS0246: The type or namespace name `List' could not be found

avatar image eatfrog · Feb 12, 2014 at 11:57 AM 0
Share

You need System.Collections.Generic in your namespace. In monodevelop, right click on list, and click resolve.

avatar image Caspert24 · Mar 22, 2015 at 03:11 PM 0
Share

I wondered where the script should be linked to? @HHameline

avatar image Caspert24 · Mar 22, 2015 at 03:23 PM 0
Share

I wondered where the script should be linked to? @HHameline

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do i make a TextArea Descend when messages happen 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to scroll a text through the trackpad of htc vive controller,How to scroll a text through trackpad of vive controller 0 Answers

Setting Scroll View Width GUILayout 1 Answer

How to make text appear when moving next to an object? 3 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