is possible to draw a sign/autograph?
Hello people, its possible use UI lineRenderer to draw something like a sign?,. Im prettly novice and for the moment I cant achieve it. This is my try:
public class DrawV2 : MonoBehaviour
{
public UILineRenderer lineRenderer;
private RectTransform RT;
private Vector2 rectPos;
private List<Vector2> points = new List<Vector2>();
private int CurrentLine = 0;
void Start()
{
lineRenderer = GetComponent<UILineRenderer>();
RT = GetComponent<RectTransform>();
rectPos = RT.position;
}
private bool drawing = false;
private bool mouseDown = false;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
points.Add(Input.mousePosition);
RefreshLine();
CurrentLine += 1; //needed to set correctly the start point of the draw
mouseDown = true;
}
if (!Input.GetMouseButtonUp(0) && mouseDown == true)
{
points.Add(Input.mousePosition);
//Debug.Log("mouse keep pressed");
RefreshLine();
CurrentLine += 1; //needed to set correctly the start point of the draw
}
if (Input.GetMouseButtonUp(0))
{
mouseDown = false;
}
}
private void RefreshLine()
{
points[CurrentLine] = new Vector2(Input.mousePosition.x - rectPos.x, Input.mousePosition.y - rectPos.y);
lineRenderer.Points = points.ToArray();
//lineRenderer.SetAllDirty(); //not sure what its do
}
}
The idea is draw when the mouse button keep pressed and if I unpress the button and press again start a new line from this new point (keeping the old line already drawed)
but have some problems: *the line is drawed "dashed" (solved disabling "Line List" on ULineRenderer)
UPDATE, the only remaining problem: *I cant stop the line drawing and later continue drawing from another point.
Sorry, GitHub hasn't been notifying me of new issues. If you want to continue drawing from another point, best to treat them as separate lines, as the Line render is as it states for rendering a single line (replicating what Unity's line renderer does but for UI) It isn't a replacement for a drawing surface, for that you would likely be better to build a new texture using the points that you are drawing on, similar to this https://forum.unity.com/threads/draw-line-on-texture.172342/
Hope that helps.