Hello everyone, I have an array with 2 elements gameObject I would like to generate random instances of this array. Basically I want them to fall from the top (at random) these objects. What is the function of the Random class let me? I Random.range used to instantiate the object in the parameters of the main camera. thanks
Use whatever you want.
Random.insideUnitCircle for example. If I understand you right.
Perhaps I did not explain well. I have one array into different elements I want to have these items fall randomly above. That is, for example instantiate stars, spheres other times. What I have posted I used to tell the main camera space of radius
Hope this helps.
List<GameObject> m_ObjList;
GameObject tempObj;
GameObject spawnPoint;
while(m_ObjList.length != 0)
{
int randNo = Random.Range(0, m_ObjList.length - 1);
//IF GameObject present in Scene, use below two lines
tempObj = m_ObjList[randNo];
tempObj.transfor.position = spawnPoint.transform.position;
//ELSE using Prefab, use below 1 line
tempObj = (GameObject) Instantiate(m_ObjList[randNo], spawnPoint.transform.position, Quaternion.Identity);
m_ObjList.removeAt(randNo);
}
NOTE: Please don’t modify orignal Obj List, create a clone use it.