- Home /
Reduce Skid Mark Alpha Gradually
For my car war game, I have generated skid marks as the car takes a turn. It's working properly, now after a few seconds passed, I want to reduce its alpha and remove it from the game. I have used trail renderer to generate skid marks.
- what shader do I require to assign to the material? 
- which way I can reduce its alpha? 
At present, I have used this kind of trail renderer material: 
Now for reducing alpha gradually, I have this kind of code:
 private IEnumerator Start()
 {
     Material myMaterial = GetComponent<Renderer>().material;
 
     while (true)
     {
         yield return new WaitForSeconds(1f);
 
         // check whether this skid trail has finished
         // (the Wheel script sets the parent to null when the skid finishes)
         if (transform.parent.name == "SkidTrailsDetachedParent")
         {
 
             // set the start colour
             //Color startCol = GetComponent<Renderer>().material.color;
             //Color startCol = myMaterial.GetColor("_EmisColor");
             Color startCol = myMaterial.GetColor("_TintColor");
 
             // wait for the persist time
             yield return new WaitForSeconds(persistTime);
 
             float t = Time.time;
 
             // fade out the skid mark
             while (Time.time < t + fadeDuration)
             {
                 float i = Mathf.InverseLerp(t, t + fadeDuration, Time.time);
                 //myMaterial.color = startCol * new Color(1, 1, 1, 1 - i);
                 //myMaterial.SetColor("_EmisColor", startCol * new Color(1f, 1f, 1f, 1f - i));
                 myMaterial.SetColor("_TintColor", startCol * new Color(1f, 1f, 1f, 1f - i));
                 yield return null;
             }
 
             // the object has faded and is now done so destroy it
             Destroy(gameObject);
         }
     }
 }
Still, it's not working for me so I expect some help from your side.
 
                 
                skid-mark-material.png 
                (22.5 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                