- Home /
Rendering a line in 2d space
I need to draw a line between two points that supports sorting layers. How do I do it?
Comment
Best Answer
Answer by Cherno · Jul 26, 2015 at 02:16 PM
Attach this script to a GameObject with a LineRenderer component. Set up the LineRenderer as usual.
using UnityEngine;
using System.Collections;
public class LineRendererSorting : MonoBehaviour {
public string layerName = "YourLayerName";
public int order = 0;
void Start () {
LineRenderer lr = GetComponent<LineRenderer>();
lr.sortingLayerName = layerName ;
lr.sortingOrder = order;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220611233037im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Background Image in a 2D game: problems of size/quality importing. What's the right workflow? 1 Answer
Small line appearing under my 2D pixel sprite - 2D Graphics not rendering properly 2 Answers
Draw only what is seen in camera 2D? 1 Answer
How can I unfocus and fade my background in a 2D game? 0 Answers
Sprites can't see 1 Answer