Pergunta

Instead of making objects spawn at random range on the Y-axis like this:

float y = Random.Range(1.723573f, 5.586497f);

How would I make objects spawn at 2 fixed locations on the Y-axis?

thank you

Foi útil?

Solução

assuming you mean you want to spawn it either at one, or the other, then try this:

float y = Random.Range(0,100) > 50 ? 1.723573f : 5.586497f;

basically, there's a 50% chance of either the first value, or the second. You could alternatively type it out like this:

float y;

if(Random.Range(0,100) > 50)
   y = 1.723573f;
else y = 5.586497f;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top