Getting variable from other script

Hello,
i’m new to unity so i have question how can i take variable from other script. I’m with friends making game with maze for project. We have Maze script to generate integer array for maze, Monster script to move monster in maze and GameManager to initialize game. Maze is generated in GameManager using Maze object and i want to get it for my Monster script. But it should be the same array so monster could walk properly.

2648805–186619–GameMenager.cs (1021 Bytes)
2648805–186621–Monster.cs (18.1 KB)
2648805–186622–Maze.cs (3.53 KB)

You should always post the code instead of uploading it using [PLAIN]``[/PLAIN] tags, because if @Kiwasi is on his phone, then he can’t help and that would be a shame, wouldn’t it?
Generally, like in C# you could just simply pass the instance of the main class to all of the script’s needing it, so for example:

YourClassTypeHere getYourClassType () {
    return this;
}

and then when you have public variables, you could simply:
int mazeSize = yourScriptInstanceHere.yourVariableName;

Try using something like on your maze script:

public MonsterScript mS;

mS = GameObject.Find("MonsterObject").GetComponent<MonsterScript>();

Then just call:

mS.DoSomething();

If you can just assign mS in the inspector, if not using GameObject.Find() in start is fine. :slight_smile: