Hi . so , i’m trying to generate an array of int’s in Managerscript.cs and then pass it’s values to another gameobject with another script called AIgen2.cs and no method seems to work
Here’s some code :
public class Managerv2 : MonoBehaviour
{
public GameObject Agent;
public int numberofagents;
public bool startbool;
public GameObject[] agentlist;
public int[] movementvector;
public int[] rotationvector;
public Rigidbody[] rb;
public int numberofiterations;
// Start is called before the first frame update
void Start()
{
numberofagents = 5;
numberofiterations = 300;
startbool = false;
agentlist = new GameObject[numberofagents];
movementvector = new int[numberofiterations];
rotationvector = new int[numberofiterations];
rb = new Rigidbody[numberofagents];
}
void GenerateMovementandRotation()
{
for (int i = 0; i <numberofiterations; i++)
{
int speedfactor = Random.Range(0, 16);
movementvector *= speedfactor;*
int rotfactor = Random.Range(-360, 360);
rotationvector = rotfactor;
}
}
void StartGeneration()
{
for (int i = 0; i < numberofagents; i++)
{
GenerateMovementandRotation();
for (int j = 0; j < numberofiterations; j++)
{
AIgen2 agentz = agentlist*.GetComponent();*
agentz.movementvector2[j] = movementvector[j];
//agentlist*.GetComponent().rotationvector2[j] = rotationvector[j];*
}
}
}
The agentlist it’s already build and has it’s values . Everything works ok , no errors except the fact that none of the values are transferred from rotationvector to rotationvector2
[[[ agentlist*.GetComponent().rotationvector2[j] = rotationvector[j]; ]]]*
I did check that the array movementvector and rotationvector have values in them before trying to pass them to movementvector2 and rotationvector2 .
Second script
public class AIgen2 : MonoBehaviour
{
public int k = 0;
public bool startgeneration = false;
public GameObject goal;
public GameObject manager;
public Managerv2 managerscript;
public int numberofiterations;
public int numberofagents;
public int[] movementvector2;
public int[] rotationvector2;
public Rigidbody rb;
}
private void Awake()
{
manager = GameObject.FindGameObjectWithTag(“manager”);
managerscript = manager.GetComponent();
numberofagents = managerscript.numberofagents;
numberofiterations = managerscript.numberofiterations;
movementvector2 = new int[numberofiterations];
rotationvector2 = new int[numberofiterations];
rb = GetComponent();
goal = GameObject.FindGameObjectWithTag(“goal”);
}
}
All the arrays have the same length . I just can’t . help me out please