public class IsPointInBoxTest : MonoBehaviour {

Transform _box;

Transform _point;

void Start () {

_box = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;

_point = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform;

_point.localScale = new Vector3(0.1f, 0.1f, 0.1f);

testPointInBox(new Vector3(0, 10, 0), new Vector3(1,1,1), Quaternion.AngleAxis(30, Vector3.up), new Vector3(0, 9.56f, 0));

testPointInBox(new Vector3(0, 10, 0), new Vector3(1,1,1), Quaternion.AngleAxis(30, Vector3.up), new Vector3(0.49f, 10, 0.49f));

testPointInBox(new Vector3(0, 10, 0), new Vector3(1,1,1), Quaternion.AngleAxis(0, Vector3.up), new Vector3(0.49f, 10, 0.49f));

}

private void testPointInBox(Vector3 boxPosition, Vector3 boxSize, Quaternion boxRotation, Vector3 testPoint) {

_box.position = boxPosition;

_box.rotation = boxRotation;

_box.localScale = boxSize;

_point.position = testPoint;

Debug.Log(IsPointInBox(boxPosition, boxSize, boxRotation, testPoint).ToString());

}

public static bool IsPointInBox(Vector3 boxPosition, Vector3 boxSize, Quaternion boxRotation, Vector3 testPoint) {

var localPoint = testPoint - boxPosition;

var rotatedPoint = Quaternion.Inverse(boxRotation) * localPoint;

return IsPointInBox(boxSize, rotatedPoint);

}

public static bool IsPointInBox(Vector3 boxPosition, Vector3 boxSize, Vector3 testPoint) {

var localPoint = testPoint - boxPosition;

return IsPointInBox(boxSize, localPoint);

}

public static bool IsPointInBox(Vector3 boxSize, Vector3 testPoint) {

return Mathf.Abs(testPoint.x) < boxSize.x/2

&& Mathf.Abs(testPoint.y) < boxSize.y/2

&& Mathf.Abs(testPoint.z) < boxSize.z/2;

}

}