NGUI HUD Text

1、NGUI HUD Text v1.13下载链接 链接:https://pan.baidu.com/s/1D0HiOyBd0SJKLAl30SF2CQ 密码:5otl
2、NGUI HUD Text简单API分析

2.1、最基本的文本Text显示
新建一个Unity场景,在场景中创建一个空物体,并为其添加一个HUD Text.cs脚本,然后创建一个脚本如下所示。注意在添加HUDText需要给他设置一个默认的Font,否则看不到效果。offset Curve为一些动画曲线。可自行调节。
这里写图片描述

using UnityEngine;
using System.Collections;
public class HUDTextTest : MonoBehaviour {
    public HUDText m_text;
    // Update is called once per frame
    void Update ()
    {
      if(Input.GetMouseButtonDown (0))
        {
            DisText("哈哈哈哈");
        }
    }
    /// <summary>
    /// 显示特定文字
    /// </summary>
    /// <param name="str">HUDText显示文字</param>
    public void DisText(string str)
    {
        ///显示文字   显示颜色   显示文字停留时间
        m_text.Add(str, Color.red, 1); 
    }
}

当玩家鼠标点击时,场景会出现如下图所示效果。
这里写图片描述
2.2、设置位置
给HUDText设置一个特定的位置,如显示在某一个特定3D物体上方之类的。设置方法如下所示

 /// <summary>
    /// HUDText需要显示的目标位置
    /// </summary>
    /// <param name="target"></param>
    public void SetTarget(Transform target)
    {
        #region 方法1
        Vector3 pos = Camera.main.WorldToViewportPoint(target.position);
        pos = UICamera.mainCamera.ViewportToWorldPoint(pos);
        pos = m_text.transform.parent.InverseTransformPoint(pos);
        pos.z = 0f;
        m_text.transform.localPosition = pos;
        #endregion
        #region 方法2
        //Vector3 vec = Camera.main.WorldToViewportPoint(target.position);
        ////转换为UI摄像机的世界坐标
        //Vector3 vec1 = UICamera.mainCamera.ViewportToWorldPoint(vec);
        //m_text.transform.position  = vec1;
        #endregion
    }

如下图我将Cube位置设置为HUDText需要显示的位置,显示效果如下图所示。
这里写图片描述
2.3、HUDText的ADD方法当显示为数字时具有一定特殊性
如下代码

 public void DisText(int intstr)
    {
        ///显示数字   显示颜色   显示文字停留时间
        m_text.Add(intstr, Color.red, 1);
    }

采用如下方法调用,显示为+1,并且当你在其未消失时点击会出现如下图所示的+2+3等一系列数字,快速持续调用会出现数字累加效果。

if(Input.GetMouseButtonDown (0))
        {
            DisText(1);
        }

这里写图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
-------------------------------------------------- NGUI: HUD Text Copyright 漏 2012-2014 Tasharen Entertainment Version 1.11 http://www.tasharen.com/forum/index.php?topic=997.0 -------------------------------------------------- Thank you for buying NGUI HUD Text! This version of HUDText has been tested with NGUI 3.4.9 If you have NGUI 2.7.0 or earlier, delete the Examples and Scripts folders, then import the contents of the hudtext_ngui270.unitypackage instead. ---------------------------------------------- !! IMPORTANT NOTE !! ---------------------------------------------- Upon importing this package into a brand-new project, you will get compile errors unless that project already has NGUI present! You'll need to import NGUI as well. If you don't have NGUI, but still want to use HUDText, then I am guessing you didn't read the package's description! But... you can still use HUDText. Get in touch with me via support@tasharen.com and I will hook you up. ---------------------------------------------- Usage: 1. Attach the HUDText script to a game object underneath your UIRoot and set the font it should use. 2. To make it follow an object drawn with another camera, attach UIFollowTarget to the same object and set its target. 3. From code, use HUDText's Add() function to add new floating text entries. You can also tweak the splines on the HUDText script, changing the motion of the text as you see fit. Video: http://www.youtube.com/watch?v=diql3UP1KQM ---------------------------------------------- Example Usage: ---------------------------------------------- HUDText hudText = GetComponent<HUDText>(); // This will show damage of 123 in red, and the message will immediately start moving. hudText.Add(-123f, Color.red, 0f); // This will show "Hello World!" and make it stay on the screen for 1 second before moving hudText.Add("Hello World!", Color.white, 1f); // If you don't want your numeric damage values to be added up, pass them as a string instead: float myDamage = 123f; hudText.Add(myDamage.ToString(), Color.red, 1f); ---------------------------------------------- If you have any questions, suggestions, comments or feature requests, please drop by the forums, found here: http://www.tasharen.com/forum/index.php?topic=997.0

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值