想做一個(gè)傷害數(shù)字顯示,結(jié)果發(fā)現(xiàn)搜索結(jié)果都太繁瑣,我覺(jué)得這么簡(jiǎn)單的功能不應(yīng)該這么麻煩?。?br> 所以做一個(gè)教程
在怪物身上創(chuàng)建一個(gè)畫(huà)布,設(shè)置渲染模式為世界空間,然后重置,修改大小,高度高一點(diǎn),因?yàn)閠ext只有在畫(huà)布范圍內(nèi)才顯示,我們要做飄升數(shù)字!
在畫(huà)布下創(chuàng)建一個(gè)text修改屬性為自己喜愛(ài)!我的設(shè)置為
FacingCamera 腳本為時(shí)刻對(duì)著攝像頭
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FacingCamera : MonoBehaviour
{
Transform[] childs;
void Start()
{
childs = new Transform[transform.childCount];
for (int i = 0; i < transform.childCount; i++)
{
childs[i] = transform.GetChild(i);
}
}
void Update()
{
for (int i = 0; i < childs.Length; i++)
{
childs[i].rotation = Camera.main.transform.rotation;
}
}
}
HudText腳本掛在text上,把text拖為預(yù)制體
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HudText : MonoBehaviour
{
Text text;
void Start()
{
text= GetComponent<Text>();
lowercenter();
}
public void lowercenter()
{
text.alignment = TextAnchor.LowerCenter;
for (int i = 28; i >14;i--)
{
text.fontSize = i;
}
Invoke("middlecenter", 0.2f);
}
public void middlecenter()
{
text.alignment = TextAnchor.MiddleCenter;
for (int i = 14; i > 7; i--)
{
text.fontSize = i;
}
Invoke("uppercenter", 0.2f);
}
public void uppercenter()
{
text.alignment = TextAnchor.UpperCenter;
for (int i = 7; i > 0; i--)
{
text.fontSize = i;
}
Destroy(gameObject, 0.2f);
}
// Update is called once per frame
void Update()
{
}
}
在怪物身上寫(xiě)個(gè)方法
public GameObject texthud;//text預(yù)制體
public Transform texthudte;//畫(huà)布位置
public void shoushang(int damage)
{
GameObject go = Instantiate(texthud, texthudte, false);
go.GetComponent<Text>().text="-"+damage.ToString();
}
在造成傷害處調(diào)用這個(gè)方法,參數(shù)為傷害值!文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-634192.html
說(shuō)了很多廢話,其實(shí)主要內(nèi)容非常少,非常簡(jiǎn)單,其他的根據(jù)需要看!文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-634192.html
到了這里,關(guān)于unity傷害數(shù)字顯示,最簡(jiǎn)單簡(jiǎn)潔的方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!