I wrote code to this a while back using ngui sprites. Its not a line renderer, but it works and it operates under the confines of the ngui sprite drawing system (so depth, etc work) with the limitations of course of it being a line drawn as a sprite.
I don't use this code much but I never see any problems with it so I assume it still works ok. Basically you create a sprite (for me just a solid white color sprite) with UILine attached, and then you can draw a line between two points. I believe SetWidthAndHeight is an extension method I use so you will need to replace that with the width and height fields of the sprite.
In the code I use, I have a static method that draws lines and uses a predefined line template so I basically just give it a parent, start and end position and it draws the line to make things easy.
[RequireComponent
(typeof (UISprite
))] public class UILine : MonoBehaviour
{
private UISprite Sprite;
public Color Color { get { return Sprite.color; } set { Sprite.color = value; } }
public int Depth { get { return Sprite.depth; } set { Sprite.depth = value; } }
private void Awake ()
{
Sprite = GetComponent <UISprite> ();
}
public void Draw (Vector2 startPoint, Vector2 endPoint, int lineWidth)
{
if (endPoint.x < startPoint.x)
{
var pointSwap = startPoint;
startPoint = endPoint;
endPoint = pointSwap;
}
var distance = Vector2.Distance (startPoint, endPoint);
var difference = startPoint - endPoint;
var angle = Vector2.Angle (Vector2.up, difference);
var center
= new Vector3
(startPoint
.x - difference
.x / 2f, startPoint
.y - difference
.y / 2f
);
transform.localPosition = center;
transform.localRotation = Quaternion.Euler (0, 0, angle);
Sprite.SetWidthAndHeight (lineWidth, distance);
}
}