РЕДАКТИРОВАТЬ : я даже не заметил ;
s, да, удалите точки с запятой, и это должно работать.
if (GameDifficulty == 3)
{
Text11.GetComponent<Text>().text = "Normal";
}
if (GameDifficulty == 2)
{
Text11.GetComponent<Text>().text = "Medium";
}
if (GameDifficulty == 1) //if there is only 3 difficulties in this line you can use just else
{
Text11.GetComponent<Text>().text = "Hard";
}
Или используйте if/else
if (GameDifficulty == 3)
{
Text11.GetComponent<Text>().text = "Normal";
}
else if (GameDifficulty == 2)
{
Text11.GetComponent<Text>().text = "Medium";
}
else if (GameDifficulty == 1) //if there is only 3 difficulties in this line you can use just else
{
Text11.GetComponent<Text>().text = "Hard";
}
и в этом случае лучше использовать switch/case
:
switch(GameDifficulty)
{
case 1:
Text11.GetComponent<Text>().text = "Hard";
break;
case 2:
Text11.GetComponent<Text>().text = "Medium";
break;
case 3:
Text11.GetComponent<Text>().text = "Normal";
break;
}
или у вас может быть словарь трудностей, например:
Dictionary<int, string> difficulties = new Dictionary<int, string>()
{
{1, "Hard" },
{2, "Medium" },
{3, "Normal" }
};
и используйте его как:
Text11.GetComponent<Text>().text = difficulties[GameDifficulty];
или enum
(существует множество способов сделать его более читабельным и простым, поэтому я закончу свои примеры этим)
enum Difficulties
{
Hard = 1,
Medium = 2,
Normal = 3
}
использование:
Text11.GetComponent<Text>().text = ((Difficulties)GameDifficulty).ToString();