well, as it says the title, ive made a small function to return a random vector3, but always returns the same values, not doing random.
It always returns 0.1,0.1,0.1
void RandomVector(Vector3 a)
{
float uno = Random.Range(0.05f, 0.15f);
float dos = Random.Range(0.05f, 0.15f);
float tres = Random.Range(0.05f, 0.15f);
a = new Vector3(uno, dos, tres);
Debug.Log(a);
}
The vector is correct the debug is just not showing the full float number change your debug for:
Debug.Log(a.ToString("F4"));
In order not to repeat a number twice you might try storing the value of the first number.
For example .
int [] array = new int[]{0,1,2,3,4,5,6};
List<int>list = null;
void Start(){
list.AddRange(array);
}
int GetUniqueRandom(bool reloadEmptyList){
if(list.Count == 0 ){
if(reloadEmptyList){
list.AddRange(array);
}
else{
return -1; // here is up to you
}
}
int rand = Random.Range(0, list.Count);
int value = list[rand];
list.RemoveAt(rand);
return value;
}
I hope it helps you.
It was a problem related to seeds and stuf, couldnt fix it, it always returned the same amount no matter what, but i found an easier way, ill put it here in case someone needs.
with only one sentence i could do all that shit.
vector3random = Random.insideUnitSphere * DistanciaMax;
Random.insideUniteSphere returns a random value inside a sphere of radius 1.