How can I get height of mesh on certain position?

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.

1 Like

-= -= -=

Something equals a subtract equals

Line 5

1 Like

Sometimes just someone else must look on it. :smile: Thanks, resolved…