(yet another) error CS0120: An object reference is required to access non-static member

OK, don’t be one of those dutchbags and say ‘I went to google and found…’ I did and found an endless loop of errors but none that helped me. I know what the issue is, but can’t code it right. this should be pretty simple for you to answer.

On script #1 (UpdateStats) I have a variable “public string sceneStudyMode;”. In the inspector I type in a name.

On script #2 (PlayerPrefsSTudy), I want to access it. I tried “UpdateStats.sceneStudyMode” and I get the error.

		////////////////////////////
			/// Study Mode
			if (PlayerPrefs.HasKey (UpdateStats.ppText + UpdateStats.sceneStudyMode + UpdateStats.victoriousText)) 
			{
				studyModeVictory = PlayerPrefs.GetFloat (UpdateStats.ppText + UpdateStats.sceneStudyMode + UpdateStats.victoriousText);		//Load					
			}
			else
			{			
				studyModeVictory = 0;
			}
		//////////////////////////

I think that it has something to do with referencing. I know what needs t be done. The variable is not in a method.

Thanks for the help and not disrespecting me.

You need to get an instance of UpdateStats and access that instance’s sceneStudyMode member. Or you should make sceneStudyMode static to access from anywhere.

If you need only one instance and access from anywhere freely you might wanna check Singleton pattern out : http://wiki.unity3d.com/index.php/Singleton

Like the message says, you need an object refetence So add one at the top of script 2:

public UpdateStats updateStats;

Assign the UpdateStats component to that variable by dragging it into the slot in the inspector. And then use that object by replacing all your exsiting references to “UpdateStats.victoriousText” (the class) etc. to “updateStats.victoriousText” (the instance of the class as dragged into the inspector)