So you can put trees and bushes and rocks on a terrain but is it possible to place a building on my terrain, because I have an Infiniteterrain script that copies the terrain as you walk turns it etc. but the world is kinda boring to explore without buildings (with loot etc) I searched for procedurall building assets but their are no free ones
No you cannot have prefabs as your mesh for the terrain editor. What I did to get around a similar problem was code my own editor script that automatically mass placed a prefab for me. These are the related files:
using UnityEngine;
public class StarPlacementHelper : MonoBehaviour
{
public Color starTint;
public Color starTint2;
public float minDensity;
public float maxDensity;
public Bounds bounds;
public SpriteRenderer[] stars;
public Vector2 minSize;
public Vector2 maxSize;
public bool randomRotation;
public void Place()
{
if (minDensity > maxDensity || maxDensity < 0)
return;
float xHalfExtent = ((float)bounds.extents.x / 2);
float yHalfExtent = ((float)bounds.extents.y / 2);
float zHalfExtent = ((float)bounds.extents.z / 2);
for (float x = bounds.center.x - xHalfExtent; x < bounds.center.x + xHalfExtent; x += getRandomDensity())
{
for (float y = bounds.center.y - yHalfExtent; y < bounds.center.y + yHalfExtent; y += getRandomDensity())
{
//skip factor
if (Random.Range(0, 9) > 1) //80 percent
continue;
for (float z = bounds.center.z - zHalfExtent; z < bounds.center.z + zHalfExtent; z += getRandomDensity())
{
//skip factor
if (Random.Range(0, 9) > 1) //80 percent
continue;
int index = Random.Range(0, stars.Length);
Color col = Color.Lerp(starTint, starTint2, Random.Range(0f, 1f));
SpriteRenderer r = Instantiate(stars[index], new Vector3(x, y, z), Quaternion.identity) as SpriteRenderer;
r.color = col;
r.transform.localScale = getRandomSize();
r.transform.parent = transform;
if (randomRotation)
r.transform.eulerAngles = new Vector3(0, 0, Random.Range(0f, 359f));
}
}
}
}
public void DeleteChildren()
{
//foreach (Transform t in transform)
// DestroyImmediate(t.gameObject);
foreach (SpriteRenderer t in transform.GetComponentsInChildren<SpriteRenderer>())
DestroyImmediate(t.gameObject);
}
private Vector3 getRandomSize()
{
//we want a square anyways
float x = Random.Range(minSize.x, maxSize.x) + minSize.x;
//float y = Random.Range(minSize.y, maxSize.y) + minSize.y;
//return new Vector3(x, y, 0);
return new Vector3(x, x, 0);
}
private float getRandomDensity()
{
return Random.Range(minDensity, maxDensity);
}
void OnDrawGizmosSelected()
{
Gizmos.color = new Color(1, 1, 1, 0.3f);
Gizmos.DrawCube(bounds.center - Vector3.forward * 20, bounds.extents);
}
}
///////////////
//place this one inside of an editor folder:
///////////////
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(StarPlacementHelper))]
public class StarPlacement : Editor
{
public override void OnInspectorGUI()
{
serializedObject.Update();
StarPlacementHelper s = target as StarPlacementHelper;
base.OnInspectorGUI();
if (GUILayout.Button("Populate"))
{
s.Place();
}
else if (GUILayout.Button("Delete Children"))
{
s.DeleteChildren();
}
}
private static void Space(int num = 1)
{
for (int i = 0; i < num; i++)
EditorGUILayout.Space();
}
}
Keep in mind that this was for a 2D project, you may have to change up some of the axis to get what you are looking for.