We've got our manager script and private variables set up, but how do we access them from other classes if they're private? While we could write separate public methods in GameBehavior to handle passing new values to the private variables, let's see whether there is a better way of doing things.
In this case, C# provides all variables with get and set properties, which are perfectly suited to our task. Think of these as methods that are automatically fired by the C# compiler whether we explicitly call them or not, similar to how Start() and Update() are executed by Unity when a scene starts.Â
get and set properties can be added to any variable, with or without an initial value, as illustrated in the following code snippet:Â
public string firstName { get; set; };
OR
public string lastName { get; set; } = "Smith";
However, using them like this doesn't add any additional benefits; for that, you need to include a code block...