I try to add aim assist lines ( Horizontal, Vertical ) crossHair that follow mouse position,
I did that with LineRenderer, and with GL.line ( OnPostRender ), but the lines lag after the mouse position.
In the clip, the white pointer is unity hardware mouse.
The crosshair lines are gameObjects with linerenderer component that follow mouse position.
Any Ideas on how to draw the lines 2D or 3D at mouse position and without lag ?
If you see this clip more attentively - you will see there some lags too. I think, that reason of big lags could be expensive calculations. Coul you post a code of your line drawing here?
Ok, the crossHair is an empty gameObject with two child gameObjects.
the parent has a script to follow mouse pos.
#pragma strict
private var ray : Ray;
private var hit : RaycastHit;
function Start () {
}
function Update () {
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit)){
transform.position = hit.point;
}
}
The Child objects has a script to add the linerenderer ( one vertical, one horizontal ).
#pragma strict
var lineMaterial:Material;
var startSize = 0.2;
var endSize = 0.02;
var c1 : Color = Color.yellow;
var c2 : Color = Color.red;
var lengthOfLineRenderer : int = 2;
private var lineRenderer : LineRenderer;
private var Pos : Vector3;
function Start(){
lineRenderer = gameObject.AddComponent(LineRenderer);
lineRenderer.material = lineMaterial;
lineRenderer.SetColors(c1, c2);
lineRenderer.SetWidth( startSize , endSize );
lineRenderer.SetVertexCount(lengthOfLineRenderer);
}
function Update () {
Pos = Vector3(transform.position.x,transform.position.y,0.0);
lineRenderer = gameObject.GetComponent(LineRenderer);
Pos.x = transform.position.x-100.0;
lineRenderer.SetPosition(0,Pos);
Pos.x = transform.position.x+100.0;
lineRenderer.SetPosition(1,Pos);
}