What i want to make is array of GameObjects type of Spheres.
In the end i want to have array with random number of Spheres and in each Sphere in the array to have for it random properties values. For example the first Sphere in the array when i will use break point i will see in it that the position is at 10,20,10 and the local scaling is 34,55,66 and the next Sphere in the array will have random values for the position and the local scaling and so on for all the Spheres in the array.
In the end i want to have on my Terrain random number of Spheres, each sphere in random position with random height for each Sphere.
I tried to make a class for that but not sure how to continue:
using UnityEngine;
using System.Collections;
public class Random_Spheres : MonoBehaviour {
// Use this for initialization
void Start () {
Objects[] objects_group = new Objects[7];
objects_group[1] = new Objects();
}
// Update is called once per frame
void Update () {
}
class Objects
{
[HideInInspector] public Vector3[] Random_Heights;
[HideInInspector] public Vector3[] Random_Positions;
[HideInInspector] public GameObject game_objects;
public Objects()
{
// code to generate random values for the class object
game_objects = GameObject.CreatePrimitive(PrimitiveType.Sphere);
Random_Heights = new Vector3[Random.Range(5,30)];
game_objects.transform.position = Random_Heights[0];
}
// user defined object
public Objects( int a, string n, bool g, int h )
{
}
}
}
What i want to do is to have two public variables so the user can set maximum and minimum range of the number of Spheres to create and also maximum and minimum range to set the heights values for each Sphere.
The way the class is now it’s not working and i just did a mess.
What i did before was working in some way but again with a mess and not good as i wanted. So i wanted to make a class for it:
I want to make it in a class or if it’s better somehow to make a structure or to tag the GameObjects somehow. I think class is better for this but not sure.
This is the old code before i tried the class:
using UnityEngine;
using System.Collections;
public class Random_Spheres : MonoBehaviour {
public int Random_SpheresNum_Min = 1, Random_SpheresNum_Max = 51;
public int Random_Height_Min = 5, Random_Height_Max = 100;
[HideInInspector] private int[] Spheres_Number;
//[HideInInspector] private Vector3[] Random_Heights;
[HideInInspector] private GameObject[] Spheres_Objects;
[HideInInspector] private int Area_Size_To_Build = 0;
[HideInInspector] private Vector3 terrainSize;
[HideInInspector] private GameObject s;
[HideInInspector] private ArrayList myNodes;
// Use this for initialization
void Start () {
Spheres_Number = new int[Random.Range (Random_SpheresNum_Min,Random_SpheresNum_Max)];
myNodes = new ArrayList ();
for (int i = 0; i < Spheres_Number.Length; i++)
{
s = GameObject.CreatePrimitive(PrimitiveType.Sphere);
s.transform.position = new Vector3 ((Random.value*461)+10, (Random.value*300)+10, 0F);
s.transform.localScale += new Vector3 (Random.Range (Random_Height_Min, Random_Height_Max), Random.Range (Random_Height_Min, Random_Height_Max), 0);
myNodes.Add(s);
}
}
// Update is called once per frame
void Update () {
}
}