untiy中让物体bird具有拖尾效果

标签: unity  拖尾效果

1.首先在工程中导入资源: Pocket RPG Weapon Trails.unitypackage(此资源里带有脚本WeaponTrail.cs),资源见链接:https://download.csdn.net/my

2.给物体bird添加脚本TestMyTrail.cs,代码如下

3.在物体bird下面添加空物体trail,并给trail添加脚本WeaponTrail.cs和组件MeshRenderer

 

public class TestMyTrail : MonoBehaviour {

    public WeaponTrail myTrail;

    private float t = 0.033f;
    private float tempT = 0;
    private float animationIncrement = 0.003f;

    void LateUpdate()
    {
        t = Mathf.Clamp(Time.deltaTime, 0, 0.066f);

        if (t > 0)
        {
            while (tempT < t)
            {
                tempT += animationIncrement;

                if (myTrail.time > 0)
                {
                    myTrail.Itterate(Time.time - t + tempT);
                }
                else
                {
                    myTrail.ClearTrail();
                }
            }

            tempT -= t;

            if (myTrail.time > 0)
            {
                myTrail.UpdateTrail(Time.time, t);
            }
        }
    }
    void Start()
    {     
        myTrail.SetTime(0.0f, 0.0f, 1.0f);// 默认没有拖尾效果
    }

    public void StartTrails()  //开始进行拖尾
    {   
        myTrail.SetTime(2.0f, 0.0f, 1.0f);//设置拖尾时长
        myTrail.StartTrail(0.5f, 0.4f);
    }

    public void ClearTrails()    //清除拖尾
    {
        myTrail.ClearTrail();
    }
}

版权声明:本文为qq_40323256原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_40323256/article/details/82527174