Unity中实现人物残影效果

今天火柴人联盟3公测了,看到一个残影的效果,很有意思,上网查询了一下实现方式,

实现思路:

将角色的网格复制出来,然后放置到新建的物体的MeshFilter组件上,每隔几十毫秒在玩家的位置生成一个,这样随着玩家移动,不断复制数个就会实现此效果。

实现代码:

cs 复制代码
public class CharacterTrail : MonoBehaviour
{
    public MeshFilter m_filter;
    public Material material;

    private void Start()
    {
        StartCoroutine(CreateMesh());
    }

    IEnumerator CreateMesh()
    {
        while (Application.isPlaying)
        {
            GameObject gameObject = new GameObject();
            gameObject.AddComponent<MeshFilter>().mesh = m_filter.mesh;
            gameObject.AddComponent<MeshRenderer>().sharedMaterial = material;
            gameObject.transform.position = transform.position;
            Destroy(gameObject, 0.7f);
            yield return new WaitForSeconds(0.1f);
        } 
    }
}

实现效果:

参考:

CHARACTER TRAIL TUTORIAL in Unity (youtube.com)

相关推荐
万兴丶12 分钟前
Unity用C#完成抖音小游戏接入引力引擎(Gravity Engine)完整指南,一篇文章讲清楚!
unity·c#·游戏引擎·抖音
WarrenMondeville2 小时前
4.Unity面向对象-接口隔离原则
java·unity·接口隔离原则
凉城a2 小时前
前端性能优化解决方案
前端·性能优化
JuiceFS3 小时前
ARM 架构 JuiceFS 性能优化:基于 MLPerf 的实践与调优
后端·性能优化
Thomas.Sir3 小时前
SpringBoot 接口全维度性能优化指南
spring boot·性能优化·状态模式
WarrenMondeville4 小时前
3.Unity面向对象-里氏替换原则
unity·游戏引擎·里氏替换原则
WarrenMondeville5 小时前
5.Unity面向对象-依赖倒置原则
unity·设计模式·依赖倒置原则
万兴丶6 小时前
Unity 用AI自动开发游戏近一年----最新Cursor使用心得
人工智能·游戏·unity·cursor
桌面运维家6 小时前
VHDX磁盘性能优化:空间回收与碎片整理指南 (Windows)
windows·性能优化
张老师带你学18 小时前
UnityVR弯曲UI
科技·游戏·unity·游戏引擎·模型