using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
public GameObject testBtn;
public Font f;
// Use this for initialization
void Start()
{
UIEventListener.Get(testBtn).onClick += CreatLabel;
}
// Update is called once per frame
void Update()
{
}
void CreatLabel(GameObject go)
{
UILabel label = NGUITools.AddChild<UILabel>(gameObject);
label.trueTypeFont = f;
label.text = "Test";
}
}
本文介绍了一个使用Unity和NGUI动态创建UILabel组件的方法。通过在脚本中定义按钮和字体资源,当按钮被点击时,会触发创建UILabel组件的过程,设置其字体和显示文本为Test。此技术适用于需要在运行时动态生成UI元素的游戏开发场景。
1636

被折叠的 条评论
为什么被折叠?



