유니티 심화

[UI] 로그인 창 만들기

송현호 2023. 9. 5. 11:36

인게임화면을 클릭했을때 프리펩화한 로그인창을 UIManager로 동적으로 불러온 다음 활성화 상태에서 버튼을 클릭했을 경우 텍스트를 출력하고 파괴하도록 하였다.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Test02UIManager : MonoBehaviour
{
    [SerializeField]
    private Test02InputField inputField;
    [SerializeField]
    private Button home;
    // Start is called before the first frame update
    void Start()
    {
        this.home.onClick.AddListener(() =>
        {
            Instantiate(inputField);
        });
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class Test02InputField : MonoBehaviour
{
    [SerializeField]
    private TMP_InputField input;
    [SerializeField]
    private Button buttonInactive;
    [SerializeField]
    private Button buttonActive;
    // Start is called before the first frame update
    void Start()
    {
        buttonActive.onClick.AddListener(() =>
        {
            Destroy(this.gameObject);
            Debug.Log(this.input.text);
        });

    }

    // Update is called once per frame
    void Update()
    {
        if(input.text == "")
        {
            buttonInactive.gameObject.SetActive(true);
            buttonActive.gameObject.SetActive(false);
        }
        else
        {
            buttonInactive.gameObject.SetActive(false);
            buttonActive.gameObject.SetActive(true);
        }
    }
}