- Home /
How to make a building automatically positioned on the terrain
Hi!
I have hundreds of buildings which don't stick with the terrain, some are floating, some are under the ground. I don't want to adjust the location of buildings one by one, the workload is too heavy. Is there any way to make those buildings positioned automatically onto the surface of terrain?
Thanks.
Are you trying to do this during run time, or in the editor?
Answer by Jeremy2300 · Mar 16, 2014 at 04:05 PM
Take a look at ExecuteInEditMode it's really pretty handy.
I like to put all my code in an OnEnable function (usually with a public boolean also to make sure what I want run will be), something like:
[ExecuteInEditMode]
public class Example : MonoBehaviour
{
public bool DO_THIS = false;
void OnEnable()
{
if(DO_THIS )
{
}
}
}
Then you can put your positioning functions in this. Probably do a Raycast down and slide the building to that point, maybe rotate it as well to match the ground slants.
Your answer
![](https://koobas.hobune.stream/wayback/20220613140407im_/https://answers.unity.com/themes/thub/images/avi.jpg)