πŸŽ‰ Celebrating 25 Years of GameDev.net! πŸŽ‰

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to read and display information from a text file into a scroll view panel in unity engine?

Started by
0 comments, last by Iamac4 1Β year ago

Here that I am creating a 2d platformer coding game in which have a dialogue panel as a questionnaire. My question is how to read and display information from a text file into a scroll view panel. I'm using the Unity game engine.

The words were not arranged:

https://www.dropbox.com/s/0uoqumbve6tq1k3/01.Capture1.PNG?dl=0​

I want a result like this:

https://www.dropbox.com/s/dvjp4jqmlsu5nf8/02.I%20want%20a%20result%20like%20this.PNG?dl=0​

Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Linq;
using TMPro;

public class importTxt : MonoBehaviour
{
    public Transform contentWindow;
    public GameObject QuestionTxtObject;

    // Start is called before the first frame update
    void Start()
    {
        //get the file from its directory of path
        string readFromFilePath = Application.streamingAssetsPath + "/QuestionsForm/" + "Java_q1" + ".txt";
        List<string> fileLines = File.ReadAllLines(readFromFilePath).ToList();

        foreach (string line in fileLines)
        {
            Instantiate(QuestionTxtObject, contentWindow);
            QuestionTxtObject.GetComponent<TMP_Text>().text = line;
        }
    }
}

None

This topic is closed to new replies.

Advertisement