Hi everyone! I finished my first game and it’s run fantastically using the preview mode of Unity 5.6 but when I built it, the game works badly because of text loads.
I’m used:
a) a script named “Lang.cs” who give me the text that I need.
b) a xml named “Lenguaje.xml” who contain all the text of the game in multiple languages.
NOTE: Those two files are located in: "APP Folder\Assets\Multilenguaje"
c) a script named “ControladorDeTextos.cs” who call the Lang.cs script and change all GUIText.
NOTE: ControladorDeTextos.cs call the function inside of Lang.cs with the parameters “string rutaTextos, string lenguajeActual”
rutaTextos = “Assets/Multilenguaje/Lenguaje.xml” // lenguajeActual = “Español” or lenguajeActual = “Ingles”
Please!
Can you help me to find what I did wrong? Can you fix it?
Thanks too much!!
Lang.cs
using System.Collections;
using System.Xml;
using UnityEngine;
public class Lang
{
private Hashtable textos;
public Lang(string ruta, string idioma)
{
XmlDocument xml = new XmlDocument();
XmlReaderSettings configuracion = new XmlReaderSettings();
configuracion.IgnoreComments = true;
configuracion.IgnoreWhitespace = true;
configuracion.ValidationType = ValidationType.DTD;
configuracion.ProhibitDtd = false;
using (XmlReader datos = XmlReader.Create(ruta, configuracion))
{
xml.Load(datos);
}
textos = new Hashtable();
var elemento = xml.DocumentElement[idioma];
if (elemento != null)
{
var elemEnum = elemento.GetEnumerator();
while (elemEnum.MoveNext())
{
var xmlItem = (XmlElement)elemEnum.Current;
textos.Add(xmlItem.GetAttribute("name"), xmlItem.InnerText);
}
}
else
{
Debug.LogError("El idioma especificado no existe: " + idioma);
}
}
public string ObtenerTexto(string nombre)
{
if (!textos.ContainsKey(nombre))
{
Debug.LogError("El nombre especificado no existe: " + nombre);
return "";
}
return (string)textos[nombre];
}
}
Lenguajes.xml
<?xml version="1.0" encoding="utf-8"?>
<languages>
<Español>
<!-- Estadisticas -->
<string name="texto_puntaje">Puntaje: </string>
<string name="texto_rondas">Ronda: </string>
<string name="texto_vidas">Vidas: </string>
<string name="texto_pausa">Presiona 'P' para pausar el Juego</string>
<!-- Menu Principal -->
<string name="texto_nombreApp">Las Crónicas del Señor Osito</string>
<string name="texto_reanudar">Reanudar</string>
<string name="texto_nuevaPartida">Nueva Partida</string>
<string name="texto_comenzar">Comenzar</string>
<string name="texto_idiomas">Idiomas</string>
<string name="texto_creditos">Créditos</string>
<string name="texto_salir">Salir</string>
<!-- Menu Idiomas -->
<string name="texto_tituloIdiomas">Idiomas</string>
<string name="texto_español">Español</string>
<string name="texto_ingles">Inglés</string>
<!-- Menu Créditos -->
<string name="texto_volver">Volver</string>
<!-- Game Over -->
<string name="texto_gameOver">¡¡Oh no!! ¡El Sr. Osito ha Muerto!</string>
<string name="texto_puntuacionObtenida">Puntuación Obtenida: </string>
</Español>
<Ingles>
<!-- Estadisticas -->
<string name="texto_puntaje">Score: </string>
<string name="texto_rondas">Wave: </string>
<string name="texto_vidas">Lifes: </string>
<string name="texto_pausa">Press 'P' to pause the Game</string>
<!-- Menu Principal -->
<string name="texto_nombreApp">The Chronicles of Mr. Teddy</string>
<string name="texto_reanudar">Resume</string>
<string name="texto_nuevaPartida">New Game</string>
<string name="texto_comenzar">Start</string>
<string name="texto_idiomas">Languages</string>
<string name="texto_creditos">Credits</string>
<string name="texto_salir">Exit</string>
<!-- Menu Idiomas -->
<string name="texto_tituloIdiomas">Languages</string>
<string name="texto_español">Spanish</string>
<string name="texto_ingles">English</string>
<!-- Menu Créditos -->
<string name="texto_volver">Back</string>
<!-- Game Over -->
<string name="texto_gameOver">Oh no!! Mr. Teddy has been Dead!</string>
<string name="texto_puntuacionObtenida">Score Obtained: </string>
</Ingles>
</languages>