Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 UTus · Sep 21, 2020 at 12:37 AM · pathfollowing

how to draw path

I specify a path and I want to draw the corresponding path with the mouse.

Is there a good way?

All answers are welcome :)

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 UTus · Sep 21, 2020 at 12:42 AM 0
Share

I want a 2D drawing

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by N-8-D-e-v · Sep 21, 2020 at 01:25 AM

Check out Line Renderers

Comment
Add comment · Show 2 · 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 UTus · Sep 21, 2020 at 02:36 AM 0
Share

I succeeded in drawing the line. However, it did not show a curve and did not implement path movement.

 public class DrawLine : ObjectBase
 {
     [Header("Line")]
     public GameObject linePrefab;
 
     [Header("Line Pooling Size")]
     public int poolingSize;
 
     private bool isDrawingStart;
     private Vector2 original$$anonymous$$ousePos;
     private Vector2 current$$anonymous$$ousePos;
 
 
     private List<GameObject> line_List = new List<GameObject>();
     private LineRenderer currentDrawingLineRenderer;
 
     protected override IEnumerator OnAwakeCoroutine()
     {
         return base.OnAwakeCoroutine();
     }
 
     private void Update()
     {
         if (Input.Get$$anonymous$$ouseButtonDown(0)) OnClick_DrawStart();
 
         if (Input.Get$$anonymous$$ouseButton(0) && isDrawingStart) Drawing();
 
         if (Input.Get$$anonymous$$ouseButtonUp(0)) OnClick_DrawEnd();
     }
 
     private void CreateLine()
     {
         if(line_List.Count < poolingSize)
         {
             GameObject temp = Instantiate(linePrefab);
             SetLineRendererPosition(temp);
             line_List.Add(temp);
         }
         else
         {
             SetLineRendererPosition(line_List[0]);
             ObjectPooling$$anonymous$$anager.$$anonymous$$oveFirstToEnd(line_List);
         }
     }
 
     private void SetLineRendererPosition(GameObject line)
     {
         currentDrawingLineRenderer = line.GetComponent<LineRenderer>();
         currentDrawingLineRenderer.SetPosition(0, original$$anonymous$$ousePos);
         currentDrawingLineRenderer.SetPosition(1, original$$anonymous$$ousePos);       
     }
 
     private void Drawing()
     {
         current$$anonymous$$ousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         currentDrawingLineRenderer.SetPosition(1, current$$anonymous$$ousePos);
     }
 
     #region Event
 
     private void OnClick_DrawStart()
     {
         isDrawingStart = true;
         original$$anonymous$$ousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         CreateLine();
     }
 
     private void OnClick_DrawEnd()
     {
         isDrawingStart = false;
     }
 
     #endregion Event
 }


alt text

캡처.png (7.5 kB)
avatar image N-8-D-e-v UTus · Sep 22, 2020 at 11:20 AM 0
Share

$$anonymous$$y bad, I didn't realize that's what you wanted, Trail renderers are what you're looking for

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

133 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

Related Questions

how to create 'pathfollow-no collision' code 2d? 1 Answer

How to add more walking path elements 0 Answers

How to prevent non-collider-objects from touching each other? 1 Answer

Problem with the climbing of stairs ( character piloted by coordinates) 0 Answers

iTween path constrained character: force original orientation? 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