Hola de nuevo, tengo otra duda, jeje en realidad varias
Desde el script "
DatosPersonaje" accedo a las variables de la clase "
Datos", algunas variables las puedo coger, otras no, y no paro de mirar el cogido y no veo el por que, no se si despues del "
datosPersonaje.edad" tengo que poner ToString(), o que deberia hacer.
CLASE
Código C#:
Ver originalusing UnityEngine;
using System.Collections;
public class Datos {
//Variables
public string nombre = "";
public int edad;
public float peso = 0;
public float altura = 0;
public string nacionalidad = "";
public string equipo = "";
public string[] demarcacion = new string[] {"Portero","Defensa Central","Defensa Lateral","Mediocentro Defensivo","Medio Lateral","Mediocentro","Mediocentro Ofensivo","Extremo","Delantero centro"};
public int indiceDemarcacion = 0;
public int numeroJugador;
public Vector2 posicionDatos = new Vector2(50, 50);
public int subirNum = 1;
}
SCRIPT
Código C#:
Ver originalusing UnityEngine;
using System.Collections;
public class DatosPersonaje : MonoBehaviour {
//ESCENA DATOS PERSONAJE
public Datos datosPersonaje;
//GUISkin
public GUISkin myGUISkin;
public GUISkin textoPorDefecto;
public GUISkin flechaDer;
public GUISkin flechaIzq;
//GUIStyle
public GUIStyle textField;
void Start(){
datosPersonaje = new Datos();
}
void Update(){
}
void OnGUI(){
//ESCENA DATOS PERSONAJE
//Modulo central trasparente
GUILayout.BeginArea(new Rect(datosPersonaje.posicionDatos.x, datosPersonaje.posicionDatos.y, Screen.width * 0.9f, Screen.height * 0.9f));
GUI.skin = myGUISkin;
GUI.Box(new Rect(Screen.width / 2 - 175, 100, 350, 350), "DATOS DEL PERSONAJE");
GUI.skin = textoPorDefecto;
GUI.Label(new Rect(Screen.width / 2 - 150, 130, 100, 25), "Nombre");
datosPersonaje.nombre = GUI.TextField (new Rect(Screen.width / 2 - 60, 128, 200, 25), datosPersonaje.nombre, 20);
GUI.Label(new Rect(Screen.width / 2 - 150, 160, 100, 25), "Edad");
//datosPersonaje.edad = GUI.TextField (new Rect(Screen.width / 2 - 60, 158, 200, 25), datosPersonaje.edad, 2);
GUI.Label(new Rect(Screen.width / 2 - 150, 190, 100, 25), "Peso");
//datosPersonaje.peso = GUI.TextField(new Rect(Screen.width / 2 - 60, 188, 200, 25), datosPersonaje.peso, 2);
GUI.Label(new Rect(Screen.width / 2 - 150, 220, 100, 25), "Altura");
//datosPersonaje.altura = GUI.TextField(new Rect(Screen.width / 2 - 60, 218, 200, 25), datosPersonaje.altura);
GUI.Label(new Rect(Screen.width / 2 - 150, 250, 100, 25), "Nacionalidad");
datosPersonaje.nacionalidad = GUI.TextField(new Rect(Screen.width / 2 - 60, 248, 200, 25), datosPersonaje.nacionalidad, 20);
GUI.Label(new Rect(Screen.width / 2 - 150, 280, 100, 25), "Equipo");
datosPersonaje.equipo = GUI.TextField(new Rect(Screen.width / 2 - 60, 278, 200, 25), datosPersonaje.equipo, 20);
GUI.Label(new Rect(Screen.width / 2 - 150, 310, 100, 25), "Demarcacion");
GUI.TextField(new Rect(Screen.width / 2 - 60, 308, 200, 25),"");
GUI.Label(new Rect(Screen.width / 2 - 47, 310, 200, 25), datosPersonaje.demarcacion[datosPersonaje.indiceDemarcacion]);
GUI.skin = flechaIzq;
if (GUI.Button(new Rect(Screen.width / 2 - 75, 311, 20, 20), "")){
//GUI.skin = myGUISkin; ----------------------------22222222222222222222222222222222222
GUI.Label(new Rect(), "datosPersonaje.subirNum--");
datosPersonaje.indiceDemarcacion--;
if (datosPersonaje.indiceDemarcacion <= 0){
datosPersonaje.indiceDemarcacion = 8;
}
}
GUI.skin = flechaDer;
if (GUI.Button(new Rect(Screen.width / 2 + 135, 311, 20, 20), "")){
GUI.Label(new Rect(), "datosPersonaje.subirNum++");
datosPersonaje.indiceDemarcacion ++;
if (datosPersonaje.indiceDemarcacion == 9){
datosPersonaje.indiceDemarcacion = 0;
}
}
GUI.skin = textoPorDefecto;
GUI.Label(new Rect(Screen.width / 2 - 150, 340, 100, 25), "Numero Jug.");
//datosPersonaje.numeroJugador = GUI.TextField(new Rect(Screen.width / 2 - 50, 338, 50, 25), datosPersonaje.numeroJugador, 2);
//Boton por si se quiere volver a la escena anterior "Informacion Usuario"
GUI.skin = myGUISkin;
if (GUI.Button(new Rect(Screen.width / 2 - 150, 380, 100, 25), "Volver")){
Application.LoadLevel("2. Informacion Usuario");
}
//Tras completar los datos del personaje, aceptar y avanzar a la proxima escena "Menu"
GUI.skin = myGUISkin;
if (GUI.Button(new Rect(Screen.width / 2 + 50, 380, 100, 25), "Aceptar")){
Application.LoadLevel("Caracteristicas");
}
GUILayout.EndArea();
}//Fin OnGUI
}//Fin clase DatosPersonaje
Por cierto, en este script la variable "
datosPersonaje.indiceDemarcacion" que la utilizo para recorrer el array
datosPersonaje.demarcacion[datosPersonaje.indiceDemarcacion], se que cuando termina el codigo mantiene el valor numerico de la posicion del array que el jugador haya escogido, (el numero 8 por ejemplo si se escoge la opcion "Delantero"), pero cuando en otro script quiero usar esa variable siempre se inicia a 0 (el uso en el otro script que digo es para pasar ese valor a otra variable que usare en un switch), ¿alquien ve en el script el por que?. La variable la declaro en la clase "Datos" y esta inicializada a 0 para que asi comience el array, pero si no le doy valor tambien sigue pasandome dicha variable a 0.
SCRIPT
Código C#:
Ver originalusing UnityEngine;
using System.Collections;
public class Caracteristicas : MonoBehaviour {
//ESCENA CARACTERISTICAS
public DatosPersonaje caractDatosPer;
public InformacionJugador caractInformacionJug;
//Variables
public int posicionSwitch;
public int i; //Para recorrer los for
void Start() {
caractDatosPer = new DatosPersonaje();
caractInformacionJug = new InformacionJugador();
posicionSwitch = this.caractDatosPer.datosPersonaje.indiceDemarcacion;//Recoge el num del array "demarcacion" para usar en el swicht el case correspondiente
}
void Update() {
}
void OnGUI () {
GUI.Label(new Rect(Screen.width / 2 , 200, 760, 250), ""+posicionSwitch);
//HABILIDADES
switch (posicionSwitch){
case 0: //Portero
//GUILayout.BeginArea(new Rect (posGUI, GUILayout.Width(Screen.width * 0.2f), GUILayout.Height(Screen.height * 1f)));
GUI.Label(new Rect(Screen.width / 2 - 370, 90, 120, 25), "Atrapar el balon");
for (i = 0; i < 10; i++){
int x = 0;
x = Screen.width / 2 - 360;
GUI.DrawTexture(new Rect(x + (72 * i), - 195, 15, 25), ultimaHabilidad);
}
GUI.Label(new Rect(Screen.width / 2 - 370, 120, 120, 25), "Reflejos");
GUI.Label(new Rect(Screen.width / 2 - 370, 150, 120, 25), "Salto");
GUI.Label(new Rect(Screen.width / 2 - 370, 180, 120, 25), "Agilidad");
GUI.Label(new Rect(Screen.width / 2 - 370, 210, 120, 25), "Valentia");
break;
case 1: //Defensa Central
break;
...............//El cogido esta acortado para que sea mas legible a los que veais este tema, dejo solo lo importante relaccionado con mi duda
}//Fin del switch
}//Fin OnGUI
}
Perdon que no hable con mucha propiedad, aun me queda un largo camino para hablar como un programador.