Skip to content

Control Sphere Size and Color

There are 3 main points in this part. First to control the size of the sphere, second determine the color of the sphere, and third randomly set the color and size of the planet.

To control the size we need to get the position of the mesh and change the position based on the radius. The mesh position variable is pointOnUnitSphere and we can multiply it with radius variable. Then the multiplication result will be used in terrainfaces.cs script.

The color of the sphere basically the result of color changing in the mesh. On planet.cs script just edit this line of the code.

void GenerateColors()
        foreach(MeshFilter m in meshFilters)
            m.GetComponent<MeshRenderer>().sharedMaterial.color = colorSettings.planetColor;

To make everything work randomly, we need to use random.range on planet.cs script to randomly determine the size and color. It needs to be done in start procedure, so the generation will be done at once and in the beginning.

private void Start()
        shapeSettings.planetRadius = Random.Range(1, 20);
        colorSettings.planetColor = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f),Random.Range(0f, 1f));



(Visited 117 times, 1 visits today)

Be First to Comment

Leave a Reply

%d bloggers like this: