NGUI HUD text 代码示例
【摘要】 //测试代码:using UnityEngine;using System.Collections; [AddComponentMenu("GameName/UseHUDExample")]public class UseHUD : MonoBehaviour{ public Transform m_target;//HUD字体出现的位置 public GameObject ...
//测试代码:
using UnityEngine;
using System.Collections;
[AddComponentMenu("GameName/UseHUDExample")]
public class UseHUD : MonoBehaviour
{
public Transform m_target;//HUD字体出现的位置
public GameObject m_hudTextPrefab;//HUD字体 prefab,不可为空
HUDText m_hudText = null;//HUD字体
// 初始化时调用
void Start ()
{
if (HUDRoot.go == null) {
GameObject.Destroy (this);
return;
}
if (m_target == null) {
m_target=this.transform;
Vector3 mpos = this.transform.position;
mpos.y += 2;
m_target.position = mpos;
}
//添加hud text到HUDRoot结点下
GameObject child = NGUITools.AddChild (HUDRoot.go, m_hudTextPrefab);
//获取HUDText
m_hudText = child.GetComponent<HUDText> ();
//添加UIFollow脚本
child.AddComponent<UIFollowTarget> ().target = m_target;
}
// 每帧调用此函数一次
void Update ()
{
if (Input.GetMouseButton (0)) {
m_hudText.Add ("+100", Color.red, 0);
}
if (Input.GetMouseButton (1)) {
m_hudText.Add ("-30", Color.green, 0);
}
if (Input.GetMouseButton (2)) {
m_hudText.Add ("漂亮!", Color.cyan, 0);
}
}
void OnClick ()
{
if (m_hudText != null) {
m_hudText.Add ("HUD TEXT", Color.red, 1.0f);
}
}
}
文章来源: czhenya.blog.csdn.net,作者:陈言必行,版权归原作者所有,如需转载,请联系作者。
原文链接:czhenya.blog.csdn.net/article/details/77751888
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)