Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Display Text from .txt file in Unity

Discussion in 'Scripting' started by HuhuWL, Aug 22, 2019.

  1. HuhuWL

    HuhuWL

    Joined:
    Apr 29, 2019
    Posts:
    12
    Hey all,

    so im trying to make a text object that shows a .txt file in my vr scene. First i tried with OnGUI, it works but it doesnt show up on vr.

    i used this code for it:

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

    public class Text : MonoBehaviour
    {

    public string txtFile = "Table_Test";
    string txtContents;
    // Start is called before the first frame update
    void Start()
    {
    TextAsset txtAssets = (TextAsset)Resources.Load(txtFile);
    txtContents = txtAssets.text;
    }

    // Update is called once per frame
    void OnGUI()
    {
    GUILayout.BeginArea(new Rect((Screen.width/2)-50, (Screen.height/2), 100, 100));
    GUILayout.Label(txtContents);
    GUILayout.EndArea();
    }
    }






    now i created a Canvas with a text object (see attached file). How can i change the code, that it will show on my canvas??

    thanks for help!
     

    Attached Files:

  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847