Problem with IF statement C#
Hi everyone :D!
My head is about to explode, I can't find why my code doesn't work. Maybe the code it's a little confusing because there're a lot of variables.
public class ScriptTexto : MonoBehaviour
{
[SerializeField] Text ElTexto;
[SerializeField] State EsLaIntro;
[SerializeField] State SMaestro;
[SerializeField] Text Prestigio;
[SerializeField] Text Estres;
[SerializeField] Text DiaP;
int PuntosPrest;
int PuntosEstr;
State estado;
string MaloJuego = "";
//-------------\\[ FIN VARIABLES ]//--------------\\
void Start()
{
estado = SMaestro;
var NuevoEstado = estado.LlamarNuevoEstado();
string partidaDIA = PlayerPrefs.GetString("PuntoGuardadoDIA");
string partidaESTADO = PlayerPrefs.GetString("PuntoGuardadoESTADO");
string estadoClase = PlayerPrefs.GetString("ClaseEscogida");
int PPrest = PlayerPrefs.GetInt("PuntosPrest");
int PEstr = PlayerPrefs.GetInt("PuntosEstr");
//-------------\\[ FIN VARIABLES ]//--------------\\
if (estadoClase == "Aplicado")
{
estado = NuevoEstado[0];
Debug.Log(estado.ToString());
if (partidaDIA == "Dia 1")
{
estado = NuevoEstado[0];
Debug.Log(estado.ToString());
if (partidaESTADO == "A1") { estado = NuevoEstado[0]; }
else if (partidaESTADO == "A1-1") { estado = NuevoEstado[1]; }
else if (partidaESTADO == "A2") { estado = NuevoEstado[2]; }
else if (partidaESTADO == "A3") { estado = NuevoEstado[3]; }
}
}
PuntosPrest = PPrest;
PuntosEstr = PEstr;
ElTexto.text = estado.LlamarStateHistoria();
}
Here I'm trying to load the game with PlayerPrefs. There're a lot of voids down the same script but I think they're not necessary to solve this problem. I don't now why, but at the first IF the State changes correctly, but at the second IF (Inside the first) there're no changes.
As you see the script executes the second IF, but no changes from the State, keeps the same.
PD: It's a text game, A1, A2, etc. are the States with text and other variables.
As you see the script executes the second IF, but no changes from the State, keeps the same.
In your code you set your state both times to the same value:
estado = NuevoEstado[0];
so why should the state change? or did i missunderstand your problme?