• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by naxrius · May 25, 2016 at 02:56 PM · unity 5uilinerendererline rendererlines

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);
         }
     
     }
 }
 
front-view.png (384.4 kB)
top-view.png (217.8 kB)
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image

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);

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image naxrius · May 25, 2016 at 05:26 PM 0
Share

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 :/

avatar image

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:

http://answers.unity3d.com/answers/1169946/view.html

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 2D Car Side Scroller question. 1 Answer

How to Stretch objects in grid layout when screen size is changed 0 Answers

Switch between set of images after pressing key 1 Answer

Unity 5.6.1 Multi display - Second monitor shows as black 2 Answers

Add Listeners to array of Buttons 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges