I’m trying to check for collision around a specific area of an object which already has a collider and I don’t want to add a child to it.
I changed my script to this and it works but I’m wondering if it can be improved:
for (int i = 0; i < 2; i++) {
Vector2 start = new Vector2 (collider.bounds.min.x, collider.bounds.min.y + (collider.bounds.size.y * i));
RaycastHit2D hit = Physics2D.Raycast (start, Vector2.right, collider.bounds.size.x, obstacleLayer);
if (hit) {
}
Debug.DrawRay (start, new Vector2 (1, 0), Color.red, 10.0f);
}
for (int i = 0; i < 2; i++) {
Vector2 start = new Vector2 (collider.bounds.min.x + (collider.bounds.size.x * i), collider.bounds.min.y);
RaycastHit2D hit = Physics2D.Raycast (start, Vector2.up, collider.bounds.size.y, obstacleLayer);
Debug.DrawRay (start, new Vector2 (0, 1), Color.white, 10.0f);
}