Random.Range not working?
I am trying to generate random x and y axis numbers but unfortunately the generated number is out of range. Code:
stageDimensions = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height));
screenPosition = new Vector2(Random.Range(2.25f,stageDimensions.x),Random.Range(-2f,2f));
and the given result was x=1.9 y=-0.2 Why does this happen?
I've never experienced Random.Range going wrong. are you screen position before you read it's x out?
Answer by blockh34d · Sep 20, 2015 at 09:44 AM
Does this happen consistently? Always 1.9? Always out of range? I have not had range() return results like that,maybe there is a mixup elsewhere? More debug output please, especially the trouble variables immediately before and after the range() call.
I found the problem...i was initializing the method to generate the random axis before i was setting the stageDimensions var. Thanks for the help and sry for this silly problem... :/
Answer by dudester · Sep 20, 2015 at 02:10 AM
seems like its doing what its supposed to do returning a range between 2.25f and what ever the stage dimension is , same with the other one , what exactly were you expecting?
@dudester The stageDimensions.x is 3.095 so how in range 2.25 and 3.0.. gives me 1.9 ??