unity global variable code example

Example 1: unity global variable

// When I want a really global variable what I do is to make a 
// static class to store this variables, like this:

public static class GlobalVariables{
	public static float pathLength; 
}
// This way every single script in my game could access this 
// variable just writing:

GlobalVariables.pathLength = 1.0f;
 
GlobalVariables.pathLength += SegmentLength;

Example 2: unity global variable

// When I want a really global variable what I do is to make a 
// static class to store this variables, like this:

public static class GlobalVariables{
	public static float pathLength; 
}
// This way every single script in my game could access this 
// variable just writing:

GlobalVariables.pathLength = 1.0f;
 
GlobalVariables.pathLength += SegmentLength;

Tags:

Misc Example