How do you call variables within a method on a static class?

This is a very basic question for anyone in here but I am very new to programing so please excuse me if this is a silly question.

I have a static class LevelManager and in it i have an intialize method

public static void initalize()
    int admin_Gold = 1000;
    int admin1_Gold = 500;
    string UserName = "Admin";
    string UserName2 = "Admin2";

In my other class called LoginManager I am trying to use UserName and UserName2 by writing:


public void LoginFunction()
    string UserName = LevelManager.UserName;
	string UserName2 = LevelManager.UserName2;
	if (userName == UserName && passWord == "password"
		 	|| userName == UserName2 && passWord == "password1")
			Debug.Log("Else Statement");

What is the proper way to write this? I am receiving this error:
“LevelManager does not contain a definition for ‘UserName’”

While you already seem to have solved your problem, I’m leaving an answer to clarify things a little bit. When you write code like the following:

public static void Initialize()
  int admin_gold = 1000;

The variable admin_gold is only usable inside that function. When Initialize() is finished, that variable effectively disappears. That’s because all variables have what’s called a Scope, that determines where they can be accessed from and how long they exist for.

You weren’t wrong thinking that you should be able to access your variables by calling LevelManager.admin_gold, the only problem was that the variables were defined in the wrong place. For you to be able to access those variables like that, your code should have looked like this:

public class LevelManager
  public static int admin_gold;
  public static int admin1_gold;

  public static void Initialize()
    admin_gold = 1000;
    admin1_gold = 5000;

The only difference is that now those variables live in the LevelManager class, not the Initialize method. You can now access and assign values to those variables from anywhere else in your game using LevelManager.admin_gold, just make sure that you call LevelManager.Initialize() before you try to access them!

public static void initalize(ref string UserName1, ref string UserName2, ref int admin1_Gold, ref int admin2_Gold)
UserName1 = “Admin1”;
UserName2 = “Admin2”;
admin1_Gold = 1000;
admin2_Gold = 500;

	public void Start()
		string str1;
		string str2;
		int int1;
		int int2;
		initalize(ref str1, ref str2, ref int1, ref int2);
		Debug.Log(string.Format(str1 + " {0} " + str2 + " {1} ",  int1,  int2));