So what I want to do is pick a random array of floats, but throw out any values between -0.25 and 0.25. Effectively eliminating 0 and values close to 0.
Here is the test code, that doesn’t work, although I think it should:
var values:float[];
private var num:float;
function Start () {
for(var i:int = 0; i<values.length; i++){
values[i] = PickRandomFloat();
}
}
function PickRandomFloat(){
num = 0.0;
num = Mathf.Lerp(-1.0, 1.0, Random.value);
if(num < 0.25 num > -0.25){
print("Picked " + num + ", picking again.");
PickAgain();
}
else{
print("Picked " + num + ",returning value");
return num;
}
}
function PickAgain(){
PickRandomFloat();
}
I have attached a package that demonstrates the issues I am seeing. Just import and hit play. In theory, this should throw out any values between -0.25 and 0.25 and pick a new number again, and if you look at the console output, it says it is throwing out invalid values, and picking again.
However, if you look in the inspector, there are 0’s in the array.
I am completely confused. Any pointers are appreciated.