Hello. I make a game on Unity 5.6.0b1 and there is a problem , where moving objects(3d model and text) leave a trail of color. I didn`t find a solution, but i hope that you will help me. I made a video with this problem.
I was literally trying to do the exact same thing and came up with this solution
For this to work your material must have a property that you want to effect over time. In my case it was transparency.
public class TrailScript : MonoBehaviour {
public int samples = 3;
Material mat;
Mesh msh;
Queue<Matrix4x4> TRS = new Queue<Matrix4x4>();
MaterialPropertyBlock mpb;
// Use this for initialization
void Start () {
mat = GetComponent<MeshRenderer> ().sharedMaterial;
msh = GetComponent<MeshFilter> ().sharedMesh;
mpb = new MaterialPropertyBlock ();
}
// Update is called once per frame
void Update () {
TRS.Enqueue (Matrix4x4.TRS(transform.position,transform.rotation,transform.localScale));
if (TRS.Count >= samples) {
TRS.Dequeue ();
}
Matrix4x4[] matrix = TRS.ToArray();
for (int i = 0; i < matrix.Length; i++) {
mpb.SetFloat ("_Transparency",(float)i/matrix.Length);
Graphics.DrawMesh (msh,matrix*,mat,0,null,0,mpb);*
-
}*
- }*
}