Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by DGames01 · Nov 24, 2019 at 07:02 PM · linerendererline rendererline drawing

line render some lines not visible

hello

I want to draw a grid on a panel using line render this is the code which i use to draw the lines

 public class paint_grid : MonoBehaviour
 {
 
     private int tempXTiles;
     private int tempYTiles;
     private float tempPanelY;
     private float tempPanelX;
     private int screenX;
     private int screenY;
     private float size;
     private LineRenderer line;
 
     public int xTiles;
     public int yTiles;
     public LineRenderer prefabline;
     public Material lineBlack;
     public Material lineWhite;
 
     // Start is called before the first frame update
     void Start()
     {
         RectTransform panel = gameObject.GetComponent<RectTransform>();
 
         line = Instantiate(prefabline,transform);
         line.material = lineBlack;
         drawGrid(panel);
     }
 
     // Update is called once per frame
     void Update()
     {
         RectTransform panel = gameObject.GetComponent<RectTransform>();
         if (tempXTiles != xTiles || tempYTiles != yTiles || screenX != Screen.width || screenY != Screen.height) {
             drawGrid(panel);
 
         }
        
     }
 
     private void drawGrid(RectTransform panel) {
         
         tempPanelX = panel.rect.width;
         tempPanelY = panel.rect.height;
 
         float xSize = tempPanelX / xTiles;
         float ySize = tempPanelY / yTiles;
 
         if( xSize < ySize) {
             size = xSize;
         }
         else {
             size = ySize;
         }
 
         // tiles +1 = linen anzahl 
         // tiles = verbindungslinen anzahl
         // +2 für anfangspunkt und endpunkt
         int lineCount = (yTiles + 1 + yTiles + xTiles + 1 + xTiles) +2;
         line.positionCount = lineCount;
         Vector3[] v3 = new Vector3[lineCount];
         float y = size * yTiles;
         int yt1 = 0;
         int yt2 = 1;
         int xt1 = 0;
         float x=0;
         int i;
         for (i =0; i< (yTiles + 1 + yTiles +1);) {
 
 
             x = x + ((xt1 ) * size);
             v3[i] = new Vector3(x , yt1 *(-y) , 0);
 
             // Reihenfolge: 0 1 1 0 0 1 1...
             yt1 = (yt1 + yt2) % 2;
 
             yt2 = (  yt2 + 1) % 2;
 
             // Reiehenfolge: 0 0 1 0 1...
             xt1 = i % 2;
             i = i + 1;
         }
         y = size * xTiles;
         yt1 = 0;
         yt2 = 1;
         xt1 = 0;
         x = 0;
         for (; i < lineCount;) {
 
             x = x + ((xt1) * size);
             v3[i] = new Vector3(yt1 * (y), -x,  0);
 
             // Reihenfolge: 0 1 1 0 0 1 1...
             yt1 = (yt1 + yt2) % 2;
 
             yt2 = (yt2 + 1) % 2;
 
             // Reiehenfolge: 0 0 1 0 1...
             xt1 = i % 2;
             i = i + 1;
 
         }
         line.SetPositions(v3);
 
         screenX = Screen.width;
         screenY = Screen.height;
         tempXTiles = xTiles;
         tempYTiles = yTiles;
     }
 }

the lines points area all corectly in the the line render, however some lines are not visible while others are just fine. If I set the line size to 2 insteeed of 1 all lines are visible, but then some are ticker than other lines, which shouldn't be. additional Infos: the panel which I draw on is part of a canvas with render mode "Screen Space Camera" the Camera is set to "Ortographic" the material use for the lines is a material with shader "UI/Default" with black oder white color

Does anyone have a tip how i could solve my problem?

Comment
Add comment
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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DGames01 · Nov 28, 2019 at 09:31 PM

i found a script to draw lines without the line render it uses the GUI to draw. It probably is not the best solution but at least it always draws all lines insteed of the line render which only draws half of them.

Link: https://wiki.unity3d.com/index.php/DrawLine

Comment
Add comment · 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
0

Answer by goutham12 · Nov 25, 2019 at 10:15 AM

just try modify this values in the start

              int numCapVertices;
              int numCornerVertices;
             void Update()
             {
                        lr.numCapVertices = numCapVertices;
                        lr.numCornerVertices = numCornerVertices;
                }

              void OnGUI()
               {
                      GUI.Label(new Rect(25, 20, 200, 30), "Num Cap Vertices");
                             numCapVertices = (int)GUI.HorizontalSlider(new Rect(165, 25, 200, 30), 
                             (float)numCapVertices, 0.0f, 20.0f);

                      GUI.Label(new Rect(25, 60, 200, 30), "Num Corner Vertices");
                                      numCornerVertices = (int)GUI.HorizontalSlider(new Rect(165, 65, 200, 30), 
                                      (float)numCornerVertices, 0.0f, 20.0f);
                      }

Now try to adjust values untill you get the best result. in my can numCapVertices is 5 and numCornerVertices is 20.

for more details

https://docs.unity3d.com/ScriptReference/LineRenderer-numCornerVertices.html https://docs.unity3d.com/ScriptReference/LineRenderer-numCapVertices.html

Comment
Add comment · 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 DGames01 · Nov 25, 2019 at 07:58 PM 0
Share

I tried it but it but it seems to only slightly change the last line drawn by my code

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

187 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

issue with LineRender start from 0 0 Answers

Raycast line renderer not drawing correctly 0 Answers

Any way to save a trail renderer? 1 Answer

If there is only one area specified by this line 0 Answers

(LineRenderer) Why does the line shrink for a second and come back to its normal size whenever a new point gets added? 0 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