Procedurally generated terrain

I made an empty game object and used an attached c# script and a prefab to procedurally generate the geometry of my design document.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mound : MonoBehaviour
{

    public GameObject moundRing;
    float height;
    float objectX;
    float objectZ;
    float objectWidth;
    float objectDepth;





    // Use this for initialization
    void Start()
    {
        height = transform.position.y;
        objectX = transform.position.x;
        objectZ = transform.position.z;
        objectWidth = transform.localScale.x;
        objectDepth = transform.localScale.z;

        for (int i = 1; i <= 17; i++)
        {
            float iFix = i;
            Color color = new Color(iFix / 17, 0, 0, 1);
            GameObject newObject = Instantiate(moundRing, new Vector3(objectX, (height - (iFix / 10)), objectZ), transform.rotation) as GameObject;
            newObject.transform.localScale = new Vector3(objectWidth + iFix, .1f, objectDepth + iFix);
            newObject.GetComponentInChildren<Renderer>().material.color = color;
           // newObject.GetComponentInChildren<MeshRenderer>().material.SetColor("_Color", color);
            //newObject.GetComponent<Shader>().a.color  = new Color(iFix, iFix, iFix, 1); 
            //newObject.GetComponentInChildren<Renderer>().material.color = color;
        }
        for (int i = 17; i <= 34; i++)
        {
            float iFix = i;
            Color color = new Color(0, iFix / 17, 0, 1);
            GameObject newObject = Instantiate(moundRing, new Vector3(objectX, (height - (iFix / 10)), objectZ), transform.rotation) as GameObject;
            newObject.transform.localScale = new Vector3(objectWidth + iFix, .1f, objectDepth + iFix);
            newObject.GetComponentInChildren<Renderer>().material.color = color;
            // newObject.GetComponentInChildren<MeshRenderer>().material.SetColor("_Color", color);
            //newObject.GetComponent<Shader>().a.color  = new Color(iFix, iFix, iFix, 1); 
            //newObject.GetComponentInChildren<Renderer>().material.color = color;
        }
        for (int i = 35; i <= 50; i++)
        {
            float iFix = i;
            Color color = new Color(0, 0, iFix / 17, 1);
            GameObject newObject = Instantiate(moundRing, new Vector3(objectX, (height - (iFix / 10)), objectZ), transform.rotation) as GameObject;
            newObject.transform.localScale = new Vector3(objectWidth + iFix, .1f, objectDepth + iFix);
            newObject.GetComponentInChildren<Renderer>().material.color = color;

        }

    }


}


1 Like

Privacy & Terms