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 & 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 > 0)
{
for (int i = 0; i < Credits.Count; i++)
{
Credits[i].transform.Translate(new Vector3(0f, 1f, 0f));
}
}
}
void CreateCredits()
{
for (int i = 0; i < 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