유니티

04/26 유니티 입력값 출력 복습 NGUI, UGUI

박준희 2021. 4. 27. 01:58

NGUI를 배우기 시작

복습을 겸하여 NGUI와UGUI로 간단히 Input Field에 값을 입력하고, 버튼을 눌러 디버그 로그로 입력값을 출력하는 씬 제작

 

개인적 사용 느낌

UGUI를 먼저 배웠기 때문에 UGUI로 구현하는 편이 아직까지는 더 좋은 것 같음

 

NGUI의 특징

버튼이나 인풋필드같은 클릭이 필요한 것들에는 Collider 컴포넌트를 추가함

UGUI의 Order in Layer를 조절하는 것을 NGUI에서는 Sprite의 Widget의 Depth를 조절

 

 

UGUI

 

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

public class UGUILogin : MonoBehaviour
{
    public Button btnLogin;
    public Text txtLogin;
    // Start is called before the first frame update
    void Start()
    {
        btnLogin.onClick.AddListener(() => 
        {
            Debug.Log(txtLogin.text);
        });
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

 

NGUI

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

public class NGUILogin : MonoBehaviour
{
    public UIButton btnLogin;
    public UILabel txtId;
    // Start is called before the first frame update
    void Start()
    {
        btnLogin.onClick.Add(new EventDelegate(() =>
        {
            Debug.Log(txtId.text);
        }));
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}