- Home /
C# accessing an array from a script in a different gameobject outside of the awake function
I’m developing a game with a randomly generated maze solving mechanic at its core, I’ve already written the maze generating code (nodemaze) so that it fills in one of its Boolean arrays (walllist) with the values of all the walls (false there’s no wall true if there is).
I’m having each wall as a separate game object with a code (wallmind) that will check if it is going to act as a solid wall or part of the pathway by checking its value in wallist see below
public class wallmind : MonoBehaviour
{
public bool wallorpath; //this value will be used later on to set the game object as a wall or path
public int slotnumber; //this is set in advance to align with the correct value in the array
public nodemaze maze; //for storing the nodemaze script
void Awake ()
{
maze = GameObject.Find ("mazzze").GetComponent <nodemaze> (); //"mazzze is the gameobject that nodemaze is attached to"
wallorpath = maze.walllist [slotnumber];
}
}
My issue is that I only seem to be able to set wallorpath during awake() which is no good because walllist hasn’t been worked out at that point (the calculations are done in the start() function of nodemaze), how do I go about accessing walllist later on in the code or somehow link the values?
any help would be appreciated I have little to no understanding of "inter-script communications" and only just managed to accomplish this by copying from the examples of online tutorials :3