How do I instantiate objects above 'sealevel'?

I have two procedurally generated meshes. One is my ‘surface’ layer, and the other is my ‘sea’ layer. Objects are instantiated on my surface layer, but even when the surface layer is below my sea layer. This is not intended.

So basically, I have ‘land’ objects spawning underwater. I do not want this.

Here is where the problem is:

			if (Physics.Raycast(new Vector3(randomX, r.bounds.max.y + 5f, randomZ), -Vector3.up, out hit)) {
				if(r.bounds.max.y > -5) {
					Instantiate(objectToPlace, hit.point, Quaternion.identity);
					currentObjects += 1;
				}
			}

The

if(r.bounds.max.y > -5) {

is my attempt at fixing the problem, but it doesn’t work. :frowning:

Try putting a MeshCollider on the sea mesh, then checking if hit.collider is the land mesh or not. If it’s not the land mesh, the raycast can be ignored.