I am currently trying to check whether the first object contains a second.
I first tried to use the bounding box, but it is defined in world space, so it is not working with my rotated cubes.
Then I found mesh bounds, but this is not working totally: nothing happens.
Here is my code:
Bounds bounds = GetComponent<MeshFilter>().mesh.bounds;
if (bounds.Contains(target.transform.position))
{
target.GetComponent<MeshRenderer>().material.color = Color.green;
}
else
{
target.GetComponent<MeshRenderer>().material.color = Color.white;
}
Then I found one more way, but still no luck:
bool IsInside(GameObject obj1, GameObject obj2)
{
Vector3 pos = obj1.transform.position;
pos = obj2.transform.InverseTransformPoint(pos);
return obj2.GetComponent<Collider>().bounds.Contains(pos);
}