Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by DDAAACCC · Jul 22, 2020 at 01:06 PM · linerendererline drawing

If there is only one area specified by this line

alt text I am drawing a line to detect objects in a specific area

However, as I draw the line, I know that if you do it wrong once, you can create two areas.

alt text

 Vector3 startPosition; 
     Vector2 preivousPos=new Vector2(100,100);  
 
     GameObject currentLineObject;
 
     LineRenderer currentLineRenderer;
 
     public Material lineMaterial;
 
     public float lineThickness;
 
     int vertexnum = 0;
     CameraManager cameraManager;
 
     private void Start()
     {
         cameraManager = Camera.main.GetComponent<CameraManager>();
     }
     void LateUpdate()
     {
         //Draw line
         if (cameraManager.mouseClickMode==3&& Input.GetMouseButtonDown(0))    //한번 누르면 계속눌러도 한번만 
         {
             StartDrawingLine();
         }
         else if (cameraManager.mouseClickMode == 3 && Input.GetMouseButton(0))  // 누르는 동안 계속
         {
             Vector2 vec2 = new Vector2(GetMousePosition().x, GetMousePosition().y);
             if (Vector2.Distance(vec2, preivousPos)>0.05)
             {
                 currentLineRenderer.positionCount++;
                 currentLineRenderer.SetPosition(vertexnum++, GetMousePosition());
             }
 
         }
         else if (cameraManager.mouseClickMode == 3 && Input.GetMouseButtonUp(0)) //누르고 난후에 
         {
             EndDrawingLine();
         }
         //Draw line
         if (cameraManager.mouseClickMode == 4 && Input.GetMouseButtonDown(0))    //한번 누르면 계속눌러도 한번만 
         {
             StartDrawingLine();
         }
         else if (cameraManager.mouseClickMode == 4 && Input.GetMouseButton(0))  // 누르는 동안 계속
         {
             Vector2 vec2 = new Vector2(GetMousePosition().x, GetMousePosition().y);
             if (Vector2.Distance(vec2, preivousPos) > 0.1)
             {
                 currentLineRenderer.positionCount++;
                 currentLineRenderer.SetPosition(vertexnum++, GetMousePosition());
             }
 
         }
         else if (cameraManager.mouseClickMode == 4 && Input.GetMouseButtonUp(0)) //누르고 난후에 
         {
             if(Vector2.Distance(startPosition,
                 new Vector2(GetMousePosition().x, GetMousePosition().y))<0.2)
             {
                 currentLineRenderer.positionCount++;
                 currentLineRenderer.SetPosition(vertexnum++, startPosition);
                 startPosition = Vector3.zero;
                 currentLineObject = null;
                 currentLineRenderer = null;
                 vertexnum = 0;
                 preivousPos = Vector2.zero;
             }
             else
             {
                 Destroy(currentLineObject);
                 startPosition = Vector3.zero;
                 currentLineObject = null;
                 currentLineRenderer = null;
                 vertexnum = 0;
                 preivousPos = Vector2.zero;
             }
         }
     }
 
   
     Vector3 GetMousePosition()
     {
         Vector3 mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
             Input.mousePosition.y, -Camera.main.transform.position.z ));
         return mousePos;
     }
 
     void StartDrawingLine()
     {
         startPosition = GetMousePosition();
         currentLineObject = new GameObject();
         currentLineObject.transform.position = startPosition;
         currentLineObject.transform.SetParent(transform);
         currentLineRenderer = currentLineObject.AddComponent<LineRenderer>();
         currentLineRenderer.positionCount = 0;
 
         currentLineRenderer.material = lineMaterial;
         currentLineRenderer.startWidth = lineThickness;
         currentLineRenderer.endWidth = lineThickness;
 
     }
 
     void EndDrawingLine()
     {
         startPosition = Vector3.zero;
         currentLineObject = null;
         currentLineRenderer = null;
         vertexnum = 0;
         preivousPos = Vector2.zero;
      
     }
 
     public void destoryLine()
     {
         for(int i=0; i<transform.childCount;i++)
         {
             GameObject.Destroy(transform.GetChild(i).gameObject);
         }
     }


  1. How can I detect objects in a painted area?

  2. Prevent two areas from appearing like photoshop lassotool

111111.png (29.0 kB)
linebake.png (27.2 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

0 Replies

· Add your reply
  • Sort: 

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

202 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

Related Questions

Any way to save a trail renderer? 1 Answer

issue with LineRender start from 0 0 Answers

How can i decrease linerenderer positions 0 Answers

Connecting objects in a list with a line that updates as you change their position 0 Answers

line render some lines not visible 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