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 romelleayala · Oct 04, 2018 at 03:21 AM · line rendererlines

Please help me achieve this

red line is where raycast direction point.
green circle is where mounseinput is

i want to draw a line like that or where the raycast direction is hitting the same object on intersection.
i already have a raycast matching object with same tag then destroy.
what i want is i wanted to draw a line the pointing to the direction like raycast.

alt text

fffffff.png (16.3 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LCStark · Oct 04, 2018 at 04:50 AM

Use a LineRenderer component. Create an empty object in your hierarchy, add a LineRenderer component to it. When you want to draw a line, set the LineRenderer.positionCount to 2, then use LineRenderer.SetPosition or LineRenderer.SetPositions to set the position of your start point and end points.

Comment
Add comment · Show 5 · 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 romelleayala · Oct 04, 2018 at 05:14 AM 0
Share

can you please give me a psuedo code ? or atleast an idea how i am going to write it.

avatar image LCStark romelleayala · Oct 04, 2018 at 05:53 AM 0
Share

Check out this manual page on how to create a line renderer in the Unity editor: LineRenderer.

In your code, where you do the raycasting, use your ray.origin as the start point, and hit.point as the end point. It's really just passing them as arguments to the line renderer's SetPosition method:

public LineRenderer lineRenderer; // attach your LineRenderer object in the editor
Ray ray;
RaycastHit2D hit;
...
lineRenderer.positionCount = 2;
lineRenderer.SetPosition(0, ray.origin);
lineRenderer.SetPosition(1, hit.point);
avatar image romelleayala LCStark · Oct 04, 2018 at 06:47 AM 0
Share

its not drawing a correct line direction

avatar image romelleayala romelleayala · Oct 04, 2018 at 06:51 AM 0
Share

ray = Camera.main.ScreenToWorldPoint (Input.mousePosition); hit = Physics2D.Raycast (ray , Vector2.zero);

         clickRight = Physics2D.Raycast (ray , Vector2.right);
         clickTop = Physics2D.Raycast (ray , Vector2.up);
         clickBottom = Physics2D.Raycast (ray , Vector2.down);
         clickLeft = Physics2D.Raycast (ray , Vector2.left);

if (clickRight.collider.gameObject.tag == tiletag4 &&clickBottom.collider.gameObject.tag == tiletag4) { Debug.Log ("bottom right");

             lineRenderer.positionCount = 3;
             lineRenderer.SetPosition(0, ray);
             lineRenderer.SetPosition(1, clickBottom.point);
             lineRenderer.SetPosition(2, clickRight.point);
             lineRenderer.enabled = true;

             Debug.DrawLine(ray, clickRight.point, Color.red);
             Debug.DrawLine(ray, clickBottom.point, Color.red);


             game$$anonymous$$anager.blockCounter (2);
             Destroy (clickBottom.collider.gameObject);
             Destroy (clickRight.collider.gameObject);

             audioSource = GetComponent<AudioSource>();
             audioSource.clip = Scored;
             audioSource.volume = _volume;
             audioSource.Play();
         }
avatar image romelleayala · Oct 04, 2018 at 06:34 AM 0
Share

how to make the line renderer show only for 1 frame.

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

91 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

Related Questions

Rendering streamline data 0 Answers

Issue drawing lines between buttons - Lines overlap the buttons 2 Answers

Is there anyway to draw smooth 2d lines? 0 Answers

Drawing Pixelated Lines 0 Answers

inconsistent lines errors?! 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