很多攻击类型游戏 掉血或者加血的同时都会出现一些飘血的样子
血条文字向上移动的效果
using UnityEngine;
public class HpPopMove : MonoBehaviour
{
//移动删除
void Start()
{
Destroy(gameObject, 2f);
}
void Update()
{
transform.Translate(transform.up * 20 * Time.deltaTime);
}
}
每次掉血的时候触发一下这里
GameObject hpPop = Instantiate(Resources.Load<GameObject>("HpPop"), GameObject.Find("Canvas").transform, false);
hpPop.AddComponent<HpPopMove>();
hpPop.transform.position = hpEnemy.transform.position + Vector3.up * 3;
hpPop.GetComponent<Text>().color = Color.red;
hpPop.GetComponent<Text>().text = "-5";