Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by AceOneFlow · Jul 23, 2016 at 10:00 PM · renderingscreenlinesdiagonal

How can I draw the diagonals of a screen?

I am trying to make a phone game and I need to split the screen in 4 sections by drawing the diagonals oof the screen. I looked over every tutorial on this site about drawing lines using LineRenderer and so far, that's the only way that I can use to draw a line wider than 1 pixel (I need it to be 3 pixels wide). The main problem is: I can only make the diagonal between the top-right corner and the bottom-left one show up when I build the app. If i run the game on my computer, through UnityRemote on my phone, both of the diagonals show up, but if I build it, only one gets drawn. This is the code I am using to draw the diagonal that is working:

 using UnityEngine;
 using System.Collections;
 
 public class Lines1 : MonoBehaviour {
 
     private LineRenderer line;
     
 
     public Material material;
 
     // Use this for initialization
     void Start () {
         line = new GameObject("Line").AddComponent<LineRenderer>();
         line.material = material;
         line.SetVertexCount(2);
         line.SetPosition(0, new Vector3(Screen.width, Screen.height));
         line.SetPosition(1, new Vector3(0, 0));
         line.SetWidth(3, 3);
         line.useWorldSpace = true;        
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }

Since I can't draw 2 lines with one LineRenderer, I created 2 objects, each one with a LineRenderer and 2 scripts, one for each line, to draw them. The only difference between the scripts are the lines where I set the position of the start point and the end point of the line. For example, in my 2nd script, I have

line.SetPosition(0, new Vector3(Screen.width,0)); line.SetPosition(1, new Vector3(0, Screen,height));

I will attach 2 photos of the game, with both of the scripts running, both on my computer and on my phone, after I build it.

This is how the game looks when I run it on my computer:alt text

This is how the game looks on my phone, after I build the app (ignore the placement of the sprites and that text in the middle of the screen...they're just a few things I will take care of after I get over this problem): alt text

I thought about using other methods, like GL.Begin(), but I am not too familiar with that, so it would be perfect if I can do everything with LineRenderers

photo1.png (234.3 kB)
screenshot-20160724-001821.png (90.8 kB)
Comment
Add comment · Show 1
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 Cherno · Jul 24, 2016 at 12:45 AM 0
Share

$$anonymous$$aybe it's a problem with the normal of the invisible line?

Anyway, another option is to use the Drawing.cs available on the User wiki.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Hybrid-Dragon · Jul 24, 2016 at 08:43 AM

Hello,

First, your second line's script should be identical to the first line's but with either Screen.width or Screen.height as a negative (just simply have a - precede the one you want to flip).

Second, you can have two lines in the same script. Just use another private variable for the second line and, optionally, a second public material for the line. After that, copy the first line's script and paste it just after with the new name for the second line, as different items referenced in scripts can't have the same name.

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 AceOneFlow · Jul 25, 2016 at 09:55 PM 0
Share

Hello! Thanks for replying. I tried your solution, but with no success...I've tried writing all the code for the lines in one script before, and I had the same result, but I tried it again, and here's how it look now: using UnityEngine; using System.Collections; using System.Linq;

 public class lines2 : $$anonymous$$onoBehaviour {
 
     private LineRenderer line;
     private LineRenderer line2;
 
     public $$anonymous$$aterial material;
 
     // Use this for initialization
     void Start()
     { //this is the line that I can't see when I build the app
         line2 = new GameObject("Line2").AddComponent<LineRenderer>();
         line2.material = material;
         line2.SetVertexCount(2);
         line2.SetPosition(0, new Vector3(Screen.width, 0));
         line2.SetPosition(1, new Vector3(0, Screen.height));
         line2.SetWidth(3, 3);
         line2.useWorldSpace = true;
         line2.SetColors(Color.black, Color.black);
         ///this is the line that shows
         line = new GameObject("Line").AddComponent<LineRenderer>();
         line.material = material;
         line.SetVertexCount(2);
         line.SetPosition(0, new Vector3(Screen.width,Screen.height));
         line.SetPosition(1, new Vector3(0, 0));
         line.SetWidth(3, 3);
         line.useWorldSpace = true;
         line.SetColors(Color.black,Color.black);
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

The problem I had with putting a $$anonymous$$us sign ("-") before any Screen.height or Screen.width parameter is that it just makes the line pop out of the frame. I can see it in the scene view, but not in game view. I don't think the problem is linked to the position of the line's ends because I tried setting some random start and end points for the line that doesn't work, so I can see that the LineRenderer does it's job, and it did. I think the problem is with those 2 corners in particular, and I have no idea how that can happen.

avatar image
0

Answer by AceOneFlow · Jul 31, 2016 at 05:35 PM

I have solved the problem. I couldn't draw 2 actual lines using LineRenderer, so I am creating two different cubes, I modify their dimensions and i position them diagonally so they both look like 2 diagonal lines. It's a lot easier this way, in my opinion.

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Screen is distort on some old iOS devices 0 Answers

Anyway to Upspamle The Game Screen? 0 Answers

GL.LINES renders in a single quadrant of the screen 0 Answers

advice for computing and rendering many, many line segments ? 0 Answers

How to integrate maxvertexcount method in my shader?? 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