- Home /
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 ?
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
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);
}
}
Your answer
Follow this Question
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