I’d like to draw a directional arrow with ui linerender. An angle is inputted and rotated using recttransform.rotation, but the line does not continue to 0,0 coordinates.
Also, even though you specify the line as a parent and the child as an arrow shape, the more you zoom in, the less you draw it properly. Is there any other solution?
There’s some part of code.
UILineRenderer line;
public UILineRenderer line2;
public float width;
float standardWidth;
[Range(0, 360)]
public float angle;
float lineLength;
float fixedScale;
RectLine rectline;
float alpha;
float arrowAngleX, arrowAngleY;
private void Awake()
{
rectline = GetComponentInChildren<RectLine>();
line = GetComponent<UILineRenderer>();
}
public void ShootingLineMake(float radius, float distance, float scale = 1)
{
alpha = 1.0f;
fixedScale = scale;
lineLength = radius * distance;
arrowAngleX = Mathf.Cos(45 * Mathf.Deg2Rad) * lineLength * 0.05f;
arrowAngleY = Mathf.Sin(45 * Mathf.Deg2Rad) * lineLength * 0.05f;
if (lineLength * Mathf.Cos(0) != 255.0f)
{
alpha = 2.0f;
}
line.Points[0] = Vector2.zero;
line.Points[1] = lineLength * Mathf.Cos(0) * Vector2.up;
line2.Points[0] = line.Points[1] + alpha * fixedScale * new Vector2(-arrowAngleX, -arrowAngleY) * 2.0f;
line2.Points[1] = line.Points[1];
line2.Points[2] = line.Points[1] + alpha * fixedScale * new Vector2(arrowAngleX, -arrowAngleY) * 2.0f;
GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, (-angle));
}