- Home /
Issue drawing lines between buttons - Lines overlap the buttons
I'm trying to draw lines between buttons, but the lines keep overlapping the buttons. I modified my script to draw the lines behind the buttons however they still overlap. Any ideas?
using UnityEngine;
using System.Collections;
// This script draws lines between elements of the Bowtie display
public class DrawLine : MonoBehaviour {
private LineRenderer lineRenderer;
private float counter;
private float dist;
private Vector3 aPos;
private Vector3 bPos;
public Transform origin;
public Transform destination;
public float lineDrawSpeed = 6f;
// Use this for initialization
void Start () {
lineRenderer = GetComponent<LineRenderer>();
aPos = new Vector3(origin.position.x, origin.position.y, origin.position.z + 0.2f); // Using these to move the lines back
bPos = new Vector3(destination.position.x, destination.position.y, destination.position.z + 0.2f);
lineRenderer.SetPosition(0, aPos);
lineRenderer.SetWidth(.02f, .02f);
dist = Vector3.Distance(origin.position, destination.position);
}
// Update is called once per frame
void Update () {
if(counter < dist){
counter += .1f/lineDrawSpeed;
float x = Mathf.Lerp(0, dist, counter);
Vector3 pointA = aPos;
Vector3 pointB = bPos;
Vector3 pointAloneLine = x * Vector3.Normalize(pointB - pointA) + pointA;
lineRenderer.SetPosition(1, pointAloneLine);
}
}
}
Answer by Prezzo · May 25, 2016 at 04:05 PM
I don't see any buttons in your code, but try to place the lineRenderer higher on the z-axis than the buttons should solve your problem. Try:
aPos = new Vector3(origin.position.x, origin.position.y, origin.position.z + 10f); // Using these to move the lines back
bPos = new Vector3(destination.position.x, destination.position.y, destination.position.z + 10f);
The buttons are referenced as "destination" in my code. In the code I posted I already attempted to move the lineRenderer further on the Z axis, by 0.2f, with no luck. Anything higher than 0.2f is too far and doesn't look right :/
Answer by M-Hanssen · May 25, 2016 at 03:18 PM
You should render the buttons on a different layer than the LineRenderer and assign those layers to different cameras. Use the camera's depth setting to change to order of rendering.
Check this answer for more details: