Hello guys I generated mesh but now I want place object on it. What is the easiest way to get max height of mesh on specific world position?
Currently I generate my ground and objects. From generated object I make Ray to find out how far from my mesh object is and then change position.y of that object by hit.distance however I must have some mistake there because it is not working correctly, what am I missing there? Can you please help me?
foreach (Transform p in resourceNodeList)
{
if (Physics.Raycast(p.localPosition, p.TransformDirection(Vector3.down), out RaycastHit hit))
{
p.transform.position = p.transform.position -= new Vector3(0, hit.distance, 0);
}
}
I tried localPosition and position but still it is not correct.
Basically I want these trees spawn exactly on mesh collider of green ground.