- Home /
 
 
               Question by 
               OBess · Jun 19, 2018 at 06:49 PM · 
                unity 2dline rendererfadeoutline drawing  
              
 
              LineRenderer fade out
I have a line, and I want to know how to make this line fade out. The first code is line - the second code is place where i draw line.
//first public class DrawLine : MonoBehaviour {
     public LineRenderer lineRenderer;
     public EdgeCollider2D edgeCol;
 
     List<Vector2> points;
     float k;
 
     public void UpdateLine (Vector2 mousePos) {
         if (points == null) {
             points = new List<Vector2> ();
             SetPoint (mousePos);
             return;
         }
         if (Vector2.Distance (points.Last (), mousePos) > .1f)
             SetPoint (mousePos);
     }
 
     void SetPoint(Vector2 point){
         points.Add (point);
 
         lineRenderer.numPositions = points.Count;
         lineRenderer.SetPosition (points.Count - 1, point);
 
         if (points.Count > 1)
             edgeCol.points = points.ToArray();
     }
 
     void OnCollisionEnter2D (Collision2D col) {
         if(col.gameObject.tag == "Player"){
             Debug.Log ("LOL");
         }
     }
 }
 //second
 public class LineCreator : MonoBehaviour {
 
     public GameObject linePrefab;
 
     DrawLine activeLine;
 
     void Update(){
         if (Input.GetMouseButtonDown (0)) {
             if (GameObject.FindGameObjectWithTag("Line"))
                 Destroy (GameObject.FindGameObjectWithTag("Line").gameObject);
             GameObject lineGO = Instantiate (linePrefab);
             activeLine = lineGO.GetComponent<DrawLine> ();
         }
         if (Input.GetMouseButtonUp (0)) {
             activeLine = null;
         }
         if (activeLine != null) {
             Vector2 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
             activeLine.UpdateLine (mousePos);
         }
     }
 }
 
              
               Comment
              
 
               
              Your answer