Created
April 4, 2019 19:13
-
-
Save tklee1975/bb1af2717dcf5d011d028d0195fe03f3 to your computer and use it in GitHub Desktop.
Demo Unity Source for "Unity UI Tips" #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class HeroInfoView1 : MonoBehaviour | |
{ | |
public Image heroImage; | |
public Text nameText; | |
public Text hpText; | |
public Text mpText; | |
public Text atkText; | |
public Text defText; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
heroImage = transform.Find("HeroUIGroup").Find("HeroImage").GetComponent<Image>(); | |
nameText = transform.Find("HeroUIGroup").Find("HeroNameText").GetComponent<Text>(); | |
} | |
public void SetHero(string name, Sprite sprite, int hp, int mp, int atk, int def) { | |
nameText.text = name; | |
heroImage.sprite = sprite; | |
hpText.text = hp.ToString("00000"); | |
mpText.text = mp.ToString("00000"); | |
atkText.text = atk.ToString("00000"); | |
defText.text = def.ToString("00000"); | |
} | |
public void CloseClicked() { | |
gameObject.SetActive(false); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class HeroInfoView2 : MonoBehaviour | |
{ | |
[Header("Hero Info UI")] | |
[SerializeField] Image m_heroImage; | |
[SerializeField] Text m_nameText; | |
[Space(5)] | |
[SerializeField] Text m_hpText; | |
[SerializeField] Text m_mpText; | |
[SerializeField] Text m_atkText; | |
[SerializeField] Text m_defText; | |
[Header("Button UI")] | |
[SerializeField] Button m_closeButton; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
m_closeButton.onClick.AddListener(CloseClicked); | |
} | |
public void SetHero(string name, Sprite sprite, int hp, int mp, int atk, int def) { | |
m_nameText.text = name; | |
m_heroImage.sprite = sprite; | |
m_hpText.text = hp.ToString("00000"); | |
m_mpText.text = mp.ToString("00000"); | |
m_atkText.text = atk.ToString("00000"); | |
m_defText.text = def.ToString("00000"); | |
} | |
void CloseClicked() { | |
gameObject.SetActive(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment