Unity make dotted line renderer

I know, that this question was asked before, but I could not find a proper answer to this. So how can I make my line dotted? I added a texture with a dot, but it just gets stretched for the length of the line, which is obviously not what I want. I'm using C# btw, if some code is needed here.

Edit: Inspector:

Edit: New Code :

public class dashedLine : MonoBehaviour
{
public Vector2 newPosition;
private LineRenderer line;

void Awake()
{
line = GetComponent<LineRenderer>();
}

void Update()
{
line.material.SetTextureOffset("_MainTex", new Vector2(Time.timeSinceLevelLoad * 4f, 0f));
line.material.SetTextureScale("_MainTex", new Vector2(newPosition.magnitude, 1f));
line.SetPosition(0, newPosition);
}
}


This is what I get:

Edit: This works now, when I use a Texture which has multiple dots in a row and put it to a material with Shader: Unlit/Transparent. I still don't know, why it's not working with a single dot.

Edit2: I had to recreate the dot texture with a single dot and it worked, so there was some issue on my side. Everything works now fine.

Apply a texture with a circle to a material, assign that material to a line renderer, and attach a script to it that will scale the texture relative to the magnitude of the line. Here's some code:

public class LineScript : MonoBehaviour
{
private LineRenderer line;

void Awake()
{
line = GetComponent<LineRenderer>();
}

void Update()
{
Vector2 newPosition = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
line.material.SetTextureOffset("_MainTex", new Vector2(Time.timeSinceLevelLoad * 4f, 0f));
line.material.SetTextureScale("_MainTex", new Vector2(newPosition.magnitude, 1f));
line.SetPosition(0, newPosition);
}
}

• Mhm I get an error, that he couldn't find my texture, my material is called Dotted_Line and the Texture, which I've put into "Albedo" is called Dot. I tried both and both didn't work. Any suggestions? – TobiasW Mar 24 '16 at 14:02
• Try using a different shader - Unlit/Transparent, or Sprites/Default. – Iggy Mar 24 '16 at 14:04
• There's nothing wrong with the material, but I guess Standard shader doesn't have a "_MainTex" properly. So using a different shader should fix it. Or download the source and look at what the textures are called in the default shader. My guess would be "_Albedo". – Iggy Mar 24 '16 at 14:10
• Okay since I have some other setup with camera and stuff I changed the code a bit, so that I can manually set the new position stuff, but the line still just gets stretched and not dotted :/ Added my code in the question. – TobiasW Mar 24 '16 at 14:14
• Okay I tried to update my question, so that I provide everything you could need to know. – TobiasW Mar 24 '16 at 14:25