Reputation: 29
Hello there fellow developers
I am trying to make a trajectory and I can draw a straight line with line renderer by getting touch direction. But I am trying to make dotted line and change color by force between green yellow and red by the force (like angry birds)
private void Draw(Vector3 forceDirection)
{
var length = Mathf.Min(forceDirection.magnitude, lineLengthMax);
var start = transform.position;
var end = start + forceDirection.normalized * length;
lineRenderer.enabled = true;
if (lineRenderer.positionCount < 2)
lineRenderer.positionCount = 2;
lineRenderer.SetPosition(0, start);
lineRenderer.SetPosition(1, end);
}
this is how I draw straight line but I could not find a way to make it dotted and colored. Since I am new to unity line renderer thing is bit complicated to me. I have searched and could not find a way to do. So if you can help me please don't hesitate.
Upvotes: 0
Views: 4616
Reputation: 321
The easier way is to create a sprite with transparent borders, like this: imported sprite with alpha channel and set "Wrap mode" to "Repeat".
Then, create a transparent material with it. Further you can just color it at runtime.
Finally, use line renderer with either "Repeat per segment" or "Tile" texture mode. Example: dotted line renderer in use
Upvotes: 0
Reputation: 2230
At least I know, There is no "dotted" line feature in Unity default line renderer, so you maybe have to impelment for your own.
Drawing line is not that complicated, especially if you want to draw only one line, you don't even have to use unity line renderer. Knowing the start point and end point, you can calculate it's tangent vector to adjust the line's rotation, and the magnitude to the line's length.
To render dotted line, you can make each "dot" aligned to the desired line, with some distance.
I've found an article maybe useful for you: Creating a dotted line in Unity
Upvotes: 2