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 ?
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 ?
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
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);
}
}