Faced a problem which i can’t figured out myself. I need the road to be a building limit, where i can’t place my building. And i don’t know what to do. We can’t put individual tag on the material of road or something like that. Maybe someone can suggest something)
Perhaps look into creating ‘areas’ on the navmesh. These are mainly for pathfinding purposes, but you can also sample a position on the mesh when placing the building to determine if it’s a non-placeable area.
You’d set up the area like this
Mark some objects with this area
And then test for the area before placing the building
if (NavMesh.SamplePosition(buildPosition, out var hit, 0f, NavMesh.GetAreaFromName("Not Placeable")))
{
// Don't allow building
}
You can remove the colliders from these objects (the navmesh uses the mesh renderer) and then put them on a layer that the camera won’t render.
Or - of course - you could not mess with the navmesh and just remove the mesh renderer instead of the collider, mark the collider as a trigger, and then use a raycast to see if you hit the collider or not and prevent placing buildings if it hits the area.
There are more complicated ways like having a ‘placeable’ texture in the mesh’s uv1 and testing the pixels under the cursor to see if it’s in the ‘placeable’ area or not. This is more complex, but allows you to have a texture ‘map’ of where buildings can go and allows for very quick setup and modification. It could even be in the alpha channel of the main texture since it’s not used.
Thanks. I chose second variant and it’s working.