So I have this script which scatters items onto a terrain object (like trees, rocks, and so on). It works! The only thing is, it gets the height of the terrain at the randomized x,z position and places the object there - so the objects are half-buried in the ground. I want to fetch the height of the prefab from which the objects are being created and spawn the objects at terrain height + half of the object height.
So I did my digging around, and I believe Renderer.bounds is what I need. But I read the documentation and I’m just not really clear on how to make it get the bounds of the object I’m about to spawn. Here’s what I have right now, to try and make my intent clear:
rend = GetComponent<Renderer>();
...
yDisplace = objectToPlace.rend.bounds.extent.y;
This of course doesn’t work because objectToPlace is a GameObject and those don’t have a Renderer function attached to them. Anyone more familiar with using Renderer who can help me point it at the right object please?