if (skill.move != 0)
{
//计算移动后的位置
Vector3 endpos = begin.transform.position + nullpos * skill.move;
//计数(看是否每帧都需要残影)
int shadownum = 0;
//使用DOTween移动
DOTween.To((t) =>
{
//线性差值移动
begin.transform.position = Vector3.Lerp(begin.transform.position, endpos, t);
shadownum++;
//if (shadownum % 2 == 0)
{
//获取每帧的模型
Mesh mesh = new Mesh();
//为了镜头稳定在模型外面套了空物体,子物体才是模型,所有要获取子物体
Transform child = begin.transform.GetChild(0);
SkinnedMeshRenderer sk = child.GetComponent<SkinnedMeshRenderer>();
sk.BakeMesh(mesh);
//创建一个能显示模型的预制体
GameObject shadow = Instantiate(Resources.Load<GameObject>("Shadow"));
//获取模型的材质球
List<Material> materials = new List<Material>();
for (int i = 0; i < sk.materials.Length; i++)
{
//使用一个可以半透明的shader创建新的材质球
Material material = new Material(Shader.Find("Custom/Face"));
material.SetTexture("_MainTex", sk.materials[i].GetTexture("_MainTex"));
material.SetTexture("_FaceTex", sk.materials[i].GetTexture("_FaceTex"));
material.color = new Color(1, 1, 1, 0.2f);
materials.Add(material);
}
//给预制体添加模型和材质
shadow.GetComponent<Shadow>().Init(mesh, materials.ToArray());
//设置位置
shadow.transform.position = child.position;
}
}, 0, 1, skill.casttime);
}
网友评论