I want to randomly assign 0 or 1 to randomNumber1
, but I failed with this code.
This is the code in Unity
public class Practice : MonoBehaviour
{
public static int randomNumber1;
public static int randomNumber2;
public class randd
{
public void randdom_dd()
{
int randomNumber1 = Random.Range(0, 2);
if (randomNumber1 == 0)
{
int randomNumber2 = 1;
}
else
{
int randomNumber2 = 0;
}
}
}
public void OnClick()
{
if (randomNumber1 == 0)
{
print("정답!");
}
else
{
print("틀렸어!");
}
}
}
I think, when I play the codes, randomNumber1
has always same int. I've tried to change the min and max in Random.Range(min, max)
and some tries, I failed.
Aucun commentaire:
Enregistrer un commentaire