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 /
  • Help Room /
avatar image
0
Question by alexander11 · Sep 14, 2016 at 01:29 PM · c#unity 53dlinesorganize

How do i Gizmos.drawLines in an order??

Hello i am trying to do this in Pic1, i tried doing it but get this(Pic2).

-Pic1 alt text


-Pic2 alt text


Here is the code so you know what i have done.

 using UnityEngine;
 using System.Collections;
 
 public class Lines: MonoBehaviour {
     
     public int xSize, zSize;
     Vector3[] points;
 
     void Start()
     {
         CreateLines();
     }
     private void CreateLines()
     {
         points = new Vector3[xSize * zSize];
         for (int i = 0, z = 0; z < zSize; z++)
         {
             for (int x = 0; x < xSize; x++, i++)
             {
                 points[i] = new Vector3(x, 0, z);
             }
         }
 
     }
     void OnDrawGizmos()
     {
         if (points == null)
         {
             return;
         }
         for (int i = 0; i < points.Length; i++)
         {
             Gizmos.DrawSphere(points[i], 0.1f);
         }
         for (int i = 0; i < points.Length-1; i++)
         {
             Gizmos.DrawLine(points[i], points[(i + 1)]);
         }
     }
 }
 


capture94.png (22.7 kB)
capture93.png (29.9 kB)
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 ScaniX · Sep 14, 2016 at 01:34 PM

If I didn't mix up xSize and zSize, this should do it:

      for (int i = 0; i < points.Length-xSize; i++) {
          Gizmos.DrawLine(points[i], points[i + xSize]);
      }
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 Good_Venson · Sep 14, 2016 at 01:50 PM

What I would do is create a function to draw connected points.

 void DrawPoints (Vector3 points) {
     for (int p = 0; p < points.Length; p++) {
         Gizmos.DrawSphere(points[p], etc...);
         if (p < points.Length-1) Gizmos.DrawLine(points[p], points[p+1]);
     }
 }

And then call it in OnDrawGizmos.

 float spacing = 1f;
 int width = 3, height = 5;
 private Vector3[] points;
 
 void OnDrawGizmos () {
     for (int x = 0; x < width; x++) {
         points = new Vector3[height];
         for (int y = 0; y < height; y++) {
             points[y] = new Vector3(x*spacing, y*spacing, 0f);
         }
         DrawPoints(points);
     }
 }

Yes, the points are being created every OnDrawGizmos, but there aren't that many points, and if it was a problem, you could just have an array of arrays of points that you create in Start or wherever. The main thing is the orientation. Just make sure that your for loops are inside each other correctly.

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

239 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 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

How do i use lines to calculate triangles on mesh?? 0 Answers

OnCollisionEnter not running. 1 Answer

How do i create Tangents on a spline?? 0 Answers

[HELP] To show wave number on a zombie survival game. 0 Answers

How to make the character walk-jump and walk (and resize the collider when crouched) ? 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