• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Curved Line Renderer 1 Answer

Convert Line Render to 3d Mesh with Collider 0 Answers

Neon / Glow effect on lines in 2d 1 Answer

Line renderer erase problem 0 Answers

How can i draw pie-charts in Unity? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges