Iam making quiz game how can i set up the here is my script i want to check if the score is from 1-10 activate this but in my way when score is 20 everything is activated?
public void CountScore(){
if (Score >= 101 - 150)
{
VerryGood.SetActive(true);
}
if (Score >= 51 - 100)
{
Good.SetActive(true);
}
if (Score >= 26 - 50)
{
NotBad.SetActive(true);
}
if (Score >= 0 - 25)
{
VerryGood.SetActive(true);
}
}
}
Try checking both if the value is above or below a number in the if-statement:
if (Score >= 101 && Score <= 150)
{
VerryGood.SetActive(true);
}
if (Score >= 51 && Score <= 100)
{
Good.SetActive(true);
}
if (Score >= 26 && Score <= 50)
{
NotBad.SetActive(true);
}
if (Score >= 0 && Score <= 25)
{
VerryGood.SetActive(true);
}
This will set only one object to Active if you are within the score range. If you want all score above 101 to be VerryGood you can replace the first if-statement with if (Score >= 101)
. Same goes for the lowest, it can be made as if (Score <= 25), it will set VerryGood active if you are below 25 Score.
Here:
public void CountScore(){
if(Score > 100)
{
Debug.Log("Score is over 100. Very good!");
}
else if(Score > 50)
{
Debug.Log("Score is between 51 and 100. Good!");
}
else if(Score > 25)
{
Debug.Log("Score is between 26 and 50. Not bad!");
}
else
{
Debug.Log("Score is under 26. Keep trying!");
}
}
}