Unity line renderer TextureMode.Tile not working properly

Viewed 595

I have a line renderer and I want to show it as a dotted line. So I set the line material as a single dot sprite material. Following is my code.

lineRenderer.material = dottedLineMaterial;
lineRenderer.textureMode = LineTextureMode.Tile;
lineRenderer.material.SetTextureOffset("_MainTex", new Vector2(1.0f, 1.0f));
lineRenderer.positionCount = 2;              
lineRenderer.SetPosition(0, clickPoints[lastIndex].position);
lineRenderer.SetPosition(1, point.transform.position);     
lineRenderer.startWidth = lineRenderer.endWidth = lineWidth; 

This is the material I used enter image description here

This is my sprite enter image description here

This is what I get as output enter image description here

My expectation is a dotted line something like this.How can I properly set this material and what's wrong I have done? enter image description here

1 Answers

material part looks fine, i guess your lineRenderer's position seem wrong.

here's example to make line follow object to your mouse it seem same as your's expectation,

hope this help.

void Update()
{
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    Vector2 dir = (mousePos - transform.position);


    lr.SetPosition(0, transform.position);
    lr.SetPosition(1, (Vector2)transform.position+ (dir.normalized * dir.magnitude);
}
Related