Domanda

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

È stato utile?

Soluzione

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top