How do I modify values in an array from a different C# script ?

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

Hello there. I think you have some confusion about scriping.
Lets say you have this array in script A, that is in ObjectA:

float[] Array1;

If you want to refear to that array, all the array, (not one value of it), dont have to declare the " " symbols, because that is only to specify one element inside the array.

Lets make a 2nd array in the same Script A that will be exactly the same as Array1

float [] Array2 = Array1;

Now, array 2 its exactly the same as Array1, same lenght, same values, they all in ObjectA.

So now, lets imagine we have a ObjectB with script B and want to make a Array3 and Array4 copies of the arrays of scriptA:

 float[] Array3 = ObjectA.GetComponent<ScriptA>().Array1;
 float[] Array4 = ObjectA.GetComponent<ScriptA>().Array2;

As you see, i used the “” symbols only for declare the array. but not for define it, (because the variable called Array3 is an array, is not just a value) We could make it also like this to be more “realistic”:

float[] Array3;
float[] Array4
GameObject ObjectA;

void Start()
{
ObjectA = GameObject.Find("ObjectA");
Array3 = ObjectA.GetComponent<ScriptA>().Array1;
Array4 = ObjectA.GetComponent<ScriptA>().Array2;
}

When you use the “” symbols, is to refear a value inside an array. If you dont use the symbols you are refearing to whole array.
I expect you to understand all, if not, please ask again, specify what you dont understand

Bye!