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 03, 2018 at 03:21 AM · raycastline renderer

on mouseclick if raycast hit with same tag drawline.

i already have a working code for raycast hit. what i want is to draw a line where the raycast hit.

![alt text][1]

upon mouseclick on intersection of any matching gameobjects. there should be a drawline.

can somebody help me with this ?

aaa.png (52.4 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

Answer by JVLVince · Oct 03, 2018 at 03:36 AM

You mean this? Unity Debug class provided an API call Debug.DrawRay. You can use this to draw ray cast.

If this is what you want, I advise you should google before asking here, it's will be faster and you can learn more than just ask. If not, please explain more what you want, I imagining that you want to use the cast to debug.

Vince

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

here is my script. on every condition on raycasting. if condition is true then draw a line accoring to how the raycast hit the object.

if (Input.GetButtonDown ("Fire1")) { 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);

         pos = Water.transform.position;
         Raycasting ();
     }


 }

 

 void Raycasting(){

     



         

     if (hit.collider == null) {
         

         //first tile tag
         if (clickTop.collider.gameObject.tag == tiletag1 && clickBottom.collider.gameObject.tag == tiletag1 && clickRight.collider.gameObject.tag == tiletag1 && clickLeft.collider.gameObject.tag == tiletag1) {


             gameManager.blockCounter (4 );
             Destroy (clickTop.collider.gameObject);

             Destroy (clickBottom.collider.gameObject);
             Destroy (clickRight.collider.gameObject);

             Destroy (clickLeft.collider.gameObject);

             Debug.Log ("up down left right");


         } else if (clickRight.collider.gameObject.tag == tiletag1 && clickBottom.collider.gameObject.tag == tiletag1 && clickLeft.collider.gameObject.tag == tiletag1) {
             Debug.Log ("left right bottom");


             gameManager.blockCounter (3 );
             Destroy (clickRight.collider.gameObject);

             Destroy (clickLeft.collider.gameObject);
             Destroy (clickBottom.collider.gameObject);


         } else if (clickRight.collider.gameObject.tag == tiletag1 && clickTop.collider.gameObject.tag == tiletag1 && clickLeft.collider.gameObject.tag == tiletag1) {
             Debug.Log ("left right top");



             gameManager.blockCounter (3);
             Destroy (clickTop.collider.gameObject);
             Destroy (clickRight.collider.gameObject);

             Destroy (clickLeft.collider.gameObject);


         } else if (clickTop.collider.gameObject.tag == tiletag1 && clickBottom.collider.gameObject.tag == tiletag1 && clickLeft.collider.gameObject.tag == tiletag1) {
             Debug.Log ("left top bottom");


             gameManager.blockCounter (3);
             Destroy (clickTop.collider.gameObject);


             Destroy (clickLeft.collider.gameObject);
             Destroy (clickBottom.collider.gameObject);

         } else if (clickRight.collider.gameObject.tag == tiletag1 && clickTop.collider.gameObject.tag == tiletag1 && clickBottom.collider.gameObject.tag == tiletag1) {
             Debug.Log ("right top bottom");

             gameManager.blockCounter (3);

             Destroy (clickTop.collider.gameObject);
             Destroy (clickRight.collider.gameObject);


             Destroy (clickBottom.collider.gameObject);


         } else if (clickTop.collider.gameObject.tag == tiletag1 && clickBottom.collider.gameObject.tag == tiletag1) {
             gameManager.blockCounter (3);

             Destroy (clickTop.collider.gameObject);
             Destroy (clickBottom.collider.gameObject);

             Debug.Log ("top bottom");

         } else if (clickLeft.collider.gameObject.tag == tiletag1 && clickRight.collider.gameObject.tag == tiletag1) {
             gameManager.blockCounter (2);

             Destroy (clickRight.collider.gameObject);

             Destroy (clickLeft.collider.gameObject);
             Debug.Log ("left right");

         } else if (clickRight.collider.gameObject.tag == tiletag1 && clickTop.collider.gameObject.tag == tiletag1) {
             Debug.Log ("top right");



             gameManager.blockCounter (2);
             Destroy (clickTop.collider.gameObject);
             Destroy (clickRight.collider.gameObject);



         } else if (clickTop.collider.gameObject.tag == tiletag1 && clickLeft.collider.gameObject.tag == tiletag1) {
             Debug.Log ("top left");



             gameManager.blockCounter (2);
             Destroy (clickTop.collider.gameObject);
             Destroy (clickLeft.collider.gameObject);

         } else if (clickLeft.collider.gameObject.tag == tiletag1 && clickBottom.collider.gameObject.tag == tiletag1) {
             Debug.Log ("bottom left");



             gameManager.blockCounter (2);
             Destroy (clickBottom.collider.gameObject);
             Destroy (clickLeft.collider.gameObject);


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




             gameManager.blockCounter (2);
             Destroy (clickBottom.collider.gameObject);
             Destroy (clickRight.collider.gameObject);

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

132 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

Related Questions

Shoot Laser 0 Answers

Raycast2D/Line Renderer offset on colliders based on mouse position 0 Answers

Raycasting along line renderer width 1 Answer

Updating line positions with reflections 1 Answer

Line Renderer Disappears 1 Answer


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