How to detect collision without using OnCollisionEnter or OnTriggerEnter?

I really need this but unable to find out the solution. I want to drag a pipe into flenge ande rotate it to fix it properly. What I have done so far is that I have attached a script to pipe where I wrote code for dragging pipe in OnMouseDrag (). Now I want to write a condition inthe same function that if pipe gets collided with flenge then rotate the pipe in the direction of mouse movement. Please answer my question if got any idea.

You could cast a collider along the direction in which the mouse is dragged, and use the result as a collision check.


You can use different types of cast, you can cast a circle, a box, a line (and their 3D counterpart if you’re working in 3D, sphere, cube, ray…)


The first thing you want to do is to determine the direction in which the mouse is going. This can be done by comparing the current position of the mouse to the last position of the mouse.


Now lets say you’re working in 3D and you cant to cast a box to check the whether or not there is something is the direction the player is dragging the pipe.

Update()
{
    //This will store information about what has been hit by the box
    RayCastHit hit;

    //This is the dimension of the box. Put what fits the most to what you're doing
    Vector3 dimensions = new Vector3(0.5f, 0.5f, 0.5f);

     if(Physics.BoxCast(transform.position, dimensions, direction, out hit))
    {
          //do here what you want to happen when there is a collision.
    }
}

simply put, this script will launch the box in the direction “direction”, and if a box hits something it will go inside the if clause. Here’s BoxCast documentation. You can specify a maximum distance also.