c# - Spawning object over various times and at two random points -
i trying make spawner getting mechanics coded in before spawn object since assuming easier part. far have created code works yet spawning points heavily skewed 1 of 2 - ratios 30:1 or more. false being heavily skewed spawn.
timeleftuntilspawn = time.time - starttime; system.random secondsbetweenspawn = new system.random (); float num2 = secondsbetweenspawn.next (1, 10); // random number between 1 , 10 'seconds' if (timeleftuntilspawn >= num2) { starttime = time.time; timeleftuntilspawn = 0; debug.log ("spawn 1 here"); system.random rnd = new system.random (); // here deciding on position of spawn after 1 has been spawned int num = rnd.next (0, 10); //random number between 0 , 10 if (num < 5) { switchspawning = false; debug.log ("false"); transform.position = spawnposition; } else if (num > 5) { switchspawning = true; debug.log ("true"); transform.position = spawnposition2; } }
first of random number int... have 10 possible numbers can be.. 0 through 10 whole numbers. check if less 5 or greater 5... have no condition if number is indeed... 5.
that's 1 out of 10 chance neither option hit.
this reason shouldn't use else if
, instead use else
alone in situation.
also there's no need search number between 0 , 10, can search 1... try this:
system.random rnd = new system.random (); // here deciding on position of spawn after 1 has been spawned float num = rnd.range (0, 1); //random number between 0 , 1 if (num < .5f) { switchspawning = false; debug.log ("false"); transform.position = spawnposition; } else { switchspawning = true; debug.log ("true"); transform.position = spawnposition2; }
Comments
Post a Comment