I've got two points which I need to create a bounding box with, and then check to see if points are within this bounding box. The end result is a marquee selection tool.
So, here is the code I started with:
var v1 = Camera.main.ScreenToViewportPoint( screenPosition1 );
var v2 = Camera.main.ScreenToViewportPoint( screenPosition2 );
var min = Vector3.Min( v1, v2 );
var max = Vector3.Max( v1, v2 );
//min.z = camera.nearClipPlane;
//max.z = camera.farClipPlane;
var bounds = new Bounds();
bounds.SetMinMax( min, max );
return bounds;
So then when I run it, it seems to create the correct bounds: Center (0.4,0.4,22.3), Extends (0.2,0.2,0.0)
And the point seems like it should be within: (0.4,0.3,22.4)
Now, my initial thoughts were that the z-index was off. However, i've tried setting that a bunch of different ways, including setting the z index of the center to 22, and the extent to 25. Nothing works.
I'm checking to see if it's contained, with:
bool unitInsideSelection = viewportBounds.Contains(camera.WorldToViewportPoint( gameObject.transform.position ) );
Where viewportBounds is the return object of the function above.
Any Thoughts?
0.0
then no point can be within except when its Z coordinate is exactly22.3
, so(0.4,0.3,22.4)
is outside as expected. \$\endgroup\$