NGUI HUD Text 血条跟随,伤害 治疗;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class my_hudText : MonoBehaviour {

    // Use this for initialization
    HUDText m_hudText;
    public Color hurtCorlor;
    public Color cureCorlor;
    public UISlider health_slider;
    public UILabel heth_label;

    int LifePoint = 100;
    int currentLifePoint=100;
    void Start ()
    {
        m_hudText = GetComponent<HUDText>();
        heth_label.text= currentLifePoint + "/" + LifePoint;

        health_slider.value = 1;
    }
	
	// Update is called once per frame
	void Update ()
    {
        if (Input.GetMouseButtonDown(0))
        {
            m_hudText.Add(-10, hurtCorlor, 1f);
            Helth(-10);
        }
        if (Input.GetMouseButtonDown(1))
        {
            m_hudText.Add(+10, cureCorlor, 1f);
            Helth(10);
        }

    }
    public void Helth(int num)
    {
        currentLifePoint += num;
        heth_label.text = currentLifePoint + "/" + LifePoint;
        health_slider.value = (float)currentLifePoint/100f;

    }
}

添加 UI follow target

血条 用UI silider做,3个物体,一个前景 一个背景,一个字体。

小技巧,创建一个空物体,然后把slide作为子物体,在空物体上 添加UI Follow Target 勾选 Disable If Invisible。会在游戏摄像机看不到的时候,将其隐藏。优化渲染 减少Draw call

扫描二维码关注公众号,回复: 2355850 查看本文章

猜你喜欢

转载自blog.csdn.net/qq2512667/article/details/81172099
HUD