I’m trying to get userSession, a variable to put in to my highscore database but i keep getting object reference error.
My SessionScript get the user’s name that is logged in from the User table database and display it.
public class SessionScript : MonoBehaviour {
public Text userName;
public static string userSession;
void Start()
{
userSession = "";
userName.text = "";
if (!DBContoller.newAcc)
userSession = MainMenu.userName;
else
userSession = CreateAcc.username;
userName.text = "Hi, " + userSession;
Debug.Log ("New Session: " + userSession + "
New Account: " + DBContoller.newAcc);
}
}
Then i want to access the userSession variable and when the user finish playing the game, it will insert the user’s highscore and stuff. Heres where is insert the score.
if(card.cardPosition == 42)
{
TimerScript.SetTimeStop();
Debug.Log("Wrong Key Press = " + wrongKeyPress);
Debug.Log("Time Passed = " + Mathf.RoundToInt(TimerScript.seconds));
wrongKeyPress = FinalWrongKeyPress;
finalSeconds = Mathf.RoundToInt(TimerScript.seconds);
if( SessionScript.userSession == null)
{
return;
}
if ( SessionScript.userSession!= null)
{
HighScoreManager.InsertScores(SessionScript.userSession,finalSeconds,wrongKeyPress);
}
GameEnd();
}
But i keep getting the error : An object reference is required to access non-static member `HighScoreManager.InsertScores(string, int, int)’
Thanks for helping me in advance!
EDIT** I realized that my InsertScore is on another scene. Therefore i can’t even reference an object as InsertScore is on another scene that is on another script.