Hi guys please i need your help.
I want render line between 2 vectors with LineRenderer component but i recieving unexpected results probably because i do something wrong with screen to world position or something.
i want connect Vector3 (0,0,0) with mouse clicked position i do it like this :
I call this after mouse click :
void CalculateDirection()
{
Vector3 startPosition= new Vector3(0,0,0);
Vector3 mousePosition = Camera.main.WorldToScreenPoint(Input.mousePosition);
Utils.DrawLine(cameraPosition,mousePosition,.1f);
}
}
I render line in this method:
public static void DrawLine(Vector3 startPosition, Vector3 endPosition, float width)
{
UtilsManager uM = Object.FindObjectOfType<UtilsManager>();
var newLine = Object.Instantiate(uM.linePrefab).GetComponent<LineRenderer>();
newLine.SetPosition(0, startPosition);
newLine.SetPosition(1, endPosition);
newLine.startWidth = width;
newLine.endWidth = width;
}
Result what i get is here :
https://gifyu.com/image/G8pk
I want line to always connect start vector(probably some transform.position i set),position of mouse click.
Thanks for help in advance.