Hi!
I want to modify an UI text at runtime when I press buttons.
The problem is that it doesn’t appear on the Android device although it does appear in the editor and in play mode.
The UI Text is child of a Canvas.
Can anybody help me?
Thanks!
using System.Collections;
using System.Collections.Generic; // For List
using UnityEngine;
using UnityEngine.UI;
using System.IO; // For parsing text file, StringReader
using System.Text;
using System;
using UnityEngine.EventSystems; // Required when using Event data.
//
public class TextImporterPrefab : MonoBehaviour
{
//
public string filePath; //Es el nombre de la ruta
public int currentLine;
public int endAtLine;
// Array donde se guardan los textos
string[] texto = new string[60];
// Para instanciar el texo
public GameObject textPrefab;
public Text myText;
//
void Start()
{
// Crear nuevo prefab de texto
GameObject nuevoTexto = Instantiate(textPrefab) as GameObject;
nuevoTexto.transform.SetParent(this.transform, false);
//
filePath = Path.Combine(Application.streamingAssetsPath, "textos.txt");
StreamReader theReader = new StreamReader(filePath, Encoding.Default); //Encoding.Default para que aparezcan las tildes y las eñes (UTF-8)
//
if (filePath != null)
{
for (int i = 0; i < 50; i++)
{
texto[i] = theReader.ReadLine();
}
theReader.Close();
//
for (int i = 0; i < 50; i++)
{
//Debug.Log(names[i]);
}
}
else
Debug.Log("Nothing");
//
if (endAtLine == 0)
{
endAtLine = texto.Length - 1;
}
myText = nuevoTexto.GetComponent<Text>();
}
//
void Update()
{
myText.text = texto[currentLine];
}
//
public void Call()
{
currentLine += 1;
}
//
}
P.D: Sorry for my bad english