Generating an object in a random position
Excuse my noobness, as I'm very new to coding. I'm trying to create an array with 10 cells, each filled with a random number between -5 and 5 (z value). I've written a few different codes but always run into the error that System.Random cannot be converted to a float value. Is there a better way to do this?
Comment
Answer by Tyche10 · May 11, 2016 at 11:07 AM
You need to explicitly make the 5 or -5 a float by adding an f or the Random.Range function will return an int (http://docs.unity3d.com/ScriptReference/Random.Range.html)
float[] floatsArray = new float[10];
for (int i = 0; i < floatsArray.Length; ++i)
{
floatsArray[i] = Random.Range(-5, 5f);
}
Your answer
Follow this Question
Related Questions
Discrete Event Simulation + Queuing 0 Answers
Rts game. 2d unit on 3d scene 0 Answers
How to make a Teleporter Pad send Player to other random Teleporter Pad? 1 Answer
Clear path from A to B 4 Answers