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.