What is the best way to make a laser targeting system that has the best performance? Also what do you think would be better, a Crosshair or a laser for targeting? Thanks.
LineRenderer.
Keep in mind that linerenderers do not batch (iirc).
Ok, I got the line renderer, but how do I script the start and end positions? I need it to start from the gun, and go to where the bullet will hit using a raycast or something. How would I go about doing that?
Hello
The raycast will give you the position where you hit (Vector3). The gun is your Origin (Vector3)
So just use it to render the line
Hello
The raycast will give you the position where you hit (Vector3). The gun is your Origin (Vector3)
So just use it to render the line
But how do I access the Line Renderer’s code to do that? It won’t let me edit Line Renderer’s code, so I can only set those variables in the inspector.
Can we see your code because it should let you.
Also try using a GetComponent call.
All I did was add the Line Renderer to my gameObject through the components menu.
Here would be the simplest code. You will have to set up the raycast on your own and cache the transform.
private var lineR : LineRenderer;
private var hit : RaycastHit;
var gun : Transform;
function Start () {
lineR = GetComponent(LineRenderer);
}
function Update () {
lineR.SetPosition(0, gun.position);
if(Physics.Raycast(transform.position, transform.forward, hit,Mathf.Infinity)) {
lineR.SetPosition(1, hit.point);
}
}