go = Instantiate(prefab, ceateLoc.position, Quaternion.Euler(0f, 0f, 270f));
go.GetComponent<net>().Start();
go.GetComponent<net>().layerWeight12 = lw12;
go.GetComponent<net>().layerWeight23 = lw23;
go.GetComponent<net>().layerWeight34 = lw34;
go.GetComponent<net>().firstGeneration = false;
go.GetComponent<net>().active = false;
go.tag = "Agent";
go.name = "car";
go.GetComponent<net>().mutate = 5;
go.GetComponent<net>().Initializate();
go.GetComponent<net>().SetMutatedWeights();
Код выше из объекта despawnController
повторяется 40 раз, и все 40 объектов имеют одинаковую переменную layerWeight12
.
public void Initializate()
{
if (firstGeneration)
{
SetRandomWeights();
}
else
{
Rigidbody2D rb = gameObject.GetComponent<Rigidbody2D>();
rb.simulated = true;
}
}
public void SetMutatedWeights()
{
if (mutate != 0)
{
MutateArrRandom(layerWeight12, mutationRate);
MutateArrRandom(layerWeight23, mutationRate);
MutateArrRandom(layerWeight34, mutationRate);
}
active = true;
}
public double[,] MutateArrRandom(double[,] Arr, double mutationFactor)
{
double[,] arrc = Arr;
for (int i = 0; i < arrc.GetLength(0); i++)
{
for (int y = 0; y < arrc.GetLength(1); y++)
{
if (RandomInt(0, 2) == 1)
{
if (RandomInt(0, 2) == 1)
{
arrc[i, y] = Arr[i, y] + mutationFactor;
}
else
{
arrc[i, y] = Arr[i, y] - mutationFactor;
}
}
}
}
return arrc;
}
Это код из объекта car(agent)
.
P.s. это только обрывки кода, на скрине я выделил все созданные объекты car(agent)