How to make this loop work? freezing on me

I’m trying to make a login screen for my game. cant get this loop to work though.
just trying to check to see if the username matches the one that was inputted with the userNameCheck variable.

Currently when i run the loop the game freezes. so im thinking the null isn’t working somehow.

can someone help? thanks.
here is an image of the login screen:

link text

void CheckForUser()
	{
		do 
		{
			
			userNameCheck = File.ReadAllText(path);
			if (userNameCheck == userNameText)
			{		
				this.FoundUser();
			}
			
			
			
		}
		while (userNameCheck != null);
		//user dosent exist
		UnityEngine.Debug.Log ("Did not find user");
		
	}
	
	
	void FoundUser()
	{
		UnityEngine.Debug.Log ("Found User");
	}

I guess you meant to restart loop if userNameCheck is null. Then:

while (userNameCheck == null);

Do while - C#

This looks like an infinite loop.

If this method:

  1. is called when userNameCheck holds a non-null value
  2. and File.ReadAllText(path) returns a non-null value
  3. and this.FoundUser() never changes userNameCheck to a null value

Then it will never exit the do-while loop

Hi

I guess what you’re trying to do is read the file 1 line at a time, because each line contains a user name. However your code is simply reading the whole file into a string every iteration of the loop, so it’ll never end up being null if the file exists.

Check out this link for reading a text file 1 line t a time: