로그인 기능 구현을 위해 LoginManager 스크립트를 만듭니다.
id, passwd InputField를 처리할 변수를 public으로 선언하고 오류메세지는 비워두겠습니다.
using UnityEngine.UI;
public class LoginManager : MonoBehaviour
{
public InputField id;
public InputField passwd;
public Text notify;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
notify.text = "";
}
저장된 id와 passwd가 존재하지 않는다면 저장합니다. 체크와 저장은 PlayerPrefs를 사용합니다.
public void SaveUserdata()
{
if (!PlayerPrefs.HasKey(id.text))
{
PlayerPrefs.SetString(id.text, passwd.text);
notify.text = "ID is created successfully";
}
else
{
notify.text = "ID presents";
}
if (!CheckInput(id.text, passwd.text))
{
return;
}
}
ID가 맞는지 비교하는 로직입니다.
public void CheckUserData()
{
string pass = PlayerPrefs.GetString(id.text);
if (passwd.text == pass)
{
SceneManager.LoadScene(1);
} else
{
notify.text = "You ID is Wrong.";
}
if (!CheckInput(id.text, passwd.text))
{ return; }
}
ID나 Passwd가 다 채워졌는지 체크하는 로직입니다.
bool CheckInput(string id, string pwd)
{
if(id == "" || pwd == "")
{
notify.text = "Input ID or Password";
return false;
} else
{
return true;
}
}
세이브 하기전 위로직을 이용해 빈곳이 없는지 체크합니다.
public void SaveUserData()
{
if (!CheckInput(id.text, passwd.text))
{
return;
}
}
하이라키에 LoginManager 빈 오브젝트를 생성하고 LoginManager.cs를 끌어다 놓습니다. ID와 Passwd변수에 해당하는 UI>Input field를 연결하고 Notify에 알림 메시지 텍스트 오브젝트를 추가합니다.
하이라키에서 Button_Create를 선택하고 On_Click()함수를 연결합니다.
Fild>Build를 열고 현재씬을 추가하고 0번이 되게 위로 올립니다.
'인생유니티 > FPS게임' 카테고리의 다른 글
비동기 로그인 (0) | 2025.04.27 |
---|---|
로그인 화면과 비동기 씬로드 - 화면UI (0) | 2025.04.26 |
옵션UI제작 (0) | 2025.04.25 |
무기 모드 추가및 효과 적용 (0) | 2025.04.24 |
Navigation (1) | 2025.04.24 |