今天火柴人联盟3公测了,看到一个残影的效果,很有意思,上网查询了一下实现方式,
实现思路:
将角色的网格复制出来,然后放置到新建的物体的MeshFilter组件上,每隔几十毫秒在玩家的位置生成一个,这样随着玩家移动,不断复制数个就会实现此效果。
实现代码:
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)