Here’s my current situation:
public class ScriptA : MonoBehaviour {
public int r;
public int c;
//content
}
public class ScriptB : MonoBehaviour {
public int[,] 2DArray;
public static int i;
public static int j;
public int n = 2;
//..
2DArray = new int[n,n] {...};
if (2DArray[i,j] == value){
//content
}
}
[CustomEditor(typeof(ScriptA))]
public class ScriptAEditor : Editor {
//...
public Vector3 methodnameA() {
//...
return new Vector3 (x,y,z)
}
public void methodnameB() {
var varname = methodnameA();
ScriptA.r = (int)varname.x;
ScriptA.c = (int)varname.z;
ScriptB.i = ScriptA.r;
ScriptB.j = ScriptA.c;
}
}
THE SITUATION:
I wrote part of the code, the salient parts to quickly illustrate how my script works.
The “i” and “j” var of the ScriptB are 2DArray’s coordinates.
The ScriptB it’s just a script where I stored the 2DArray and the world’s states. I’ll use the “i” and “j” var to calculate the passability of the neighbours tiles.
In the scriptAEditor I use the r and c vars from the scriptA and position a GameObject on a grid. After positioning the GameObject I get back a new Vector3 value from the methodnameA().
In the methodnameB() I assign the value of the Vector3 got from the first method, to the var varname of the methodnameB(), then I assign varname.x and varname.z to the variables r and c from the ScriptA. Then I assign ScriptA.r and ScriptA.c to ScriptB.i and ScriptB.j.
In this way the GameObject position matches with the 2DArray coordinates, in order to manage the state of the world as terrain tag, such passable tiles and similiar.
THE PROBLEM:
I need to serialize the variables to keep them even after pressing the Play Button. I tried to use [SerializeField] on the var i and var j, then on the var r and c and then again, on the methodnameA() to serialize the Vector3. But nothing worked…
Probably I didn’t understand very well how serialization works. Can somebody explain me and tell me how to serialize those values in the custom input script and bring in the game? Thank you very much ![]()