int randomX = new int (6.5f, 3.2f, 0f);
How should I get this too work? My current errors are Error CS1729: ‘int’ does not contain a constructor that takes ‘3’ arguments (CS1729) (Assembly-CSharp). Also I don’t want any in betweens, only those 3.
int randomX = new int (6.5f, 3.2f, 0f);
How should I get this too work? My current errors are Error CS1729: ‘int’ does not contain a constructor that takes ‘3’ arguments (CS1729) (Assembly-CSharp). Also I don’t want any in betweens, only those 3.
float numbers = new float[6.5f, 3.2f, 0f];
int randomIndex = Random.Range(0, 3);
float randomFloatFromNumbers = numbers[randomIndex];
First you need the type float, if you want decimals. Next, you can define your list of numbers to chose from in an array. Then you need a random index and lastly you can pick from you array an element by addressing the random index.
Use arrays then pick a random index from the array length
I will do this in JS but it is easy to convert to C#
function Update(){
//create an array
var randomX = new Array(6.5, 3.2, 0.0);
// use random range .. Random.Range(min,max).
var MyIndex = Random.Range(0,(randomX.length));
//show the result only to make sure.
Debug.Log(randomX[MyIndex]);
}
Hope this helps
If you’re just learning scripting, can write something easy to understand instead. Code with things you almost understand is a good way to learn, but too much new stuff and you just make more and more errors.
This rolls 1, 2 or 3 and picks the number based on it:
int roll = Random.Range(1,4); // 1, 2 or 3
int num=6.5f; // if you roll a 1, it keep this
if(n==2) num=3.2f;
if(n==3) num=0.0f;