3d游戏中,角色或敌人受到伤害或者BUFF等处理需要特效,还需要飘字。下面将使用Unity预设来做飘字效果。
1、创建prefab(可以创建多种),以伤害为例:
2、飘字管理器:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class FloatTextManager : MonoBehaviour
{
private static FloatTextManager instance = null;
private FloatTextManager() { }
public static FloatTextManager GetInstance()
{
return instance;
}
float _floatTime = 1;
const float _up = 2.7f;
public void Swpan(string str, Transform parent)
{
GameObject obj = GameObject.Instantiate(Resources.Load<GameObject>("FloatText/Word_hurt"));
Transform word = obj.transform;
word.SetParent(parent);
word.GetComponentInChildren<TextMesh>().text = str;
Vector3 pos = new Vector3(BXRandomUtil.Range(-1.5f, 1.5f), BXRandomUtil.Range(0, 1), 0);
word.localPosition = pos;
Vector3 point = new Vector3(Screen.width / 2, 0, Screen.height / 2);
word.LookAt(Camera.main.ScreenToWorldPoint(point));
float posY = pos.y + _up;
word.DOMoveY(posY, _floatTime).OnComplete(()=>{ GameObject.Destroy(obj1);
}
}
|