using UnityEngine;
using UnityEngine.UI;
public class ButtonTest : MonoBehaviour
{
public UIButton btn;
// Start is called before the first frame update
void Start()
{
this.btn.onClick.Add(new EventDelegate(() =>
{
Debug.Log("click");
}));
}
}
using UnityEngine;
using UnityEngine.UI;
public class ButtonTest : MonoBehaviour
{
public UISlider slider;
[Range(0f,1f)]
public float sliderValue;
// Start is called before the first frame update
void Start()
{
StartCoroutine(this.CheckSliderValue());
}
private IEnumerator CheckSliderValue()
{
while (true)
{
this.slider.value = this.sliderValue;
yield return null;
}
}
}
using UnityEngine;
using UnityEngine.UI;
public class ButtonTest : MonoBehaviour
{
public UIButton btn;
public UILabel label;
// Start is called before the first frame update
void Start()
{
this.btn.onClick.Add(new EventDelegate(() =>
{
Debug.Log("click");
this.label.text = "Hello World";
}));
//버튼 클릭 시 문구가 변경되도록 설정
}
}
using UnityEngine;
using UnityEngine.UI;
public class ButtonTest : MonoBehaviour
{
public UIButton btn;
public UILabel label;
public UISprite thumb;
// Start is called before the first frame update
void Start()
{
this.btn.onClick.Add(new EventDelegate(() =>
{
Debug.Log("click");
this.label.text = "Hello World";
thumb.spriteName = "user_info_profile_monster";
//snap 버튼과 같음
this.thumb.MakePixelPerfect();
}));
}
//NGUI의 경우엔 스프라이트 파일명을 그대로 붙혀넣기 하면 된다.
//버튼 클릭시 썸네일이 변경되도록 설정
입력창 배경 이미지에다 해당 컴포넌트 붙혀주기배경 스트라이프 내부에 라벨 오브젝트 만든 후 배경 bg 컴포넌트에 assign박스 콜라이더 크기 bg사이즈에 맞춘 후 isTrigger 체크해주기
따로 스크립트를 작성하지 않아도 작동된다.
using UnityEngine;
using UnityEngine.UI;
public class UILogin : MonoBehaviour
{
public UILoginButton uiLoginButton;
// Start is called before the first frame update
void Start()
{
this.Init();
}
public void Init()
{
this.uiLoginButton.btnClose.onClick.Add(new EventDelegate(() =>
{
this.gameObject.SetActive(false);
}));
this.uiLoginButton.btnLogin.onClick.Add(new EventDelegate(() =>
{
var username = this.uiLoginButton.inputUsername.text="";
var pwd = this.uiLoginButton.inputPassword.text="";
Debug.LogFormat("{0} {1}", username, pwd);
}));
this.uiLoginButton.btnLogin.onClick.Add(new EventDelegate(() =>
{
Debug.Log("LogIn");
}));
//-------------------------------------------------------
this.uiLoginButton.btnForgotPwd.onClick.Add(new EventDelegate(() =>
{
Debug.Log("Remember");
this.uiLoginButton.isChecked = true;
this.uiLoginButton.arrChecks[0].SetActive(false);
this.uiLoginButton.arrChecks[1].SetActive(true);
}));
this.uiLoginButton.btnCheck.onClick.Add(new EventDelegate(() =>
{
Debug.Log("Forget");
this.uiLoginButton.isChecked = false;
this.uiLoginButton.arrChecks[0].SetActive(true);
this.uiLoginButton.arrChecks[1].SetActive(false);
}));
}
}
using UnityEngine;
using UnityEngine.UI;
public class UILoginButton : MonoBehaviour
{
public UIButton btnClose;
public UIButton btnLogin;
public InputField inputUsername;
public InputField inputPassword;
public UIButton btnForgotPwd;
public UIButton btnCheck;
public bool isChecked;
public GameObject[] arrChecks;
}