Instantiating inside an area only.

In my game players can instantiate objects, but they should only be able to do it inside of an area.
alt text

I only want to be able to instantiate objects inside of that box

I have tried using Vector3.distance, but that will only use a single int and not like a x and y distance.

Any suggestions?

Get the coordinates of the corners, have the instantiate check before it actual instantiates if the X/Y/Z’s are within bounds… We kinda did a project like this in CS class. But yeah, just check it before, if it passes all tests, than instantiate, if not, then ignore.

So, if spot to spawn is above this and is below this, and is on this side and this side of this of both the x and z, then spawn, else, dont do anything =).

if(X <= __ && Y <= __ && Z <= __ && X >= __ && Y >= __ && Z >= __)

Try creating a trigger collider to define where you are allowed to instantiate objects inside and then in a script that has a reference to that collider use this:

if(myCollider.bounds.Contains(ray.GetPoint(hitdistance) ) )


This works with box colliders, sphere colliders, etc, etc.