Altering array stored in other script

Hi,

I make an array in one script though I want to edit that same array in another script, how do I do this ?

Currently I just return the array to the editing-script in it's Start(). Though when I new the array in the editing-script the array's are no longer linked... Any way to fix this ? (other than setting the array again in the non-editing-script after I new-ed it in the editing-script ?)

So basecly: How do I keep two array's in two different script constantly sinced. So when either is changed, the other is immediatly changed too (this is a 2way street).

Thanks !

If you want 'sync' (two copies that update each other), you'd probably want to SendMessage or directly call an syncing function when either array's values change, to the other script.

But if you want one array that both scripts can get at, maybe you can post some code for us to review, because that should just work like any other array: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Components.html

Something like this:

Script A

public class A
{
  public GameObject tiles[,];

  .. whatever you need to do in this script ..
}

Script B

public class B
{
  void SomeFunction()
  {
    A scriptA = GameObject.Find("something_with_Script_A_on_it").GetComponent("A");
    scriptA.tiles[0,1].someProperty = 1.4;
   ... etc ...
  }
}

Of course, you can also make A a plugin script (put into a Plugins folder) so it's more 'global' and/or you can have an Awake or Start function find an A component script so you only have to do that once.

Sounds like you want to return a ref variable. This is not trivial, but you could read more about it here http://stackoverflow.com/questions/296913/how-to-return-a-reference-to-a-string-in-c

If you want to pass it in another function you could do this with ref

void MyOtherFunc(ref MyClass myClassInstance)

Then all changes in this function will happen on the original.

http://msdn.microsoft.com/en-us/library/14akc2c7.aspx