private Spawned SpawnObjectInMesh(int index, int trashArrayPos) { Mesh m = spawnArea[index].mesh; Transform t = center[index]; SpawnedList curRow = spawnable_SmallTrash[trashArrayPos]; Spawned current = curRow[curRow.Count - 1]; Vector3 vec = m.GetRandomPointInsideConvex(); vec = t.TransformPoint(vec); RaycastHit info; LayerMask mask = LayerMask.GetMask("Ground"); if (Physics.Raycast(vec, Vector3.down, out info, Mathf.Infinity, mask)) { current.gameObject.transform.position = info.point + Vector3.up * 0.2f; current.gameObject.transform.rotation = Random.rotation; current.gameObject.SetActive(true); curRow.Remove(current); spawned_SmallTrash[trashArrayPos].Add(current); LevelBalancing.SetTrashValue(current.personalTrashValue); return(current); } return(null); }
public Spawned SpawnSpecificTrashArea(int indexForm, int indexSpawnArea) { Spawned ret = null; TA_SHAPES standard = TA_SHAPES.Plane_Small; SpawnedList spawnable_curList = spawnable_TrashAreas[indexForm]; SpawnedList spawned_curList = spawned_TrashAreas[indexForm]; Spawned curPopped; int lastPos; if (spawnable_curList.Count == 0) { lastPos = 0; curPopped = spawned_curList[0]; spawned_curList.RemoveAt(0); spawnable_curList.Add(curPopped); } else { lastPos = spawnable_TrashAreas[indexForm].Count - 1; curPopped = spawnable_curList[lastPos]; } curPopped.gameObject.SetActive(true); //trashAreaHandler.Spawn(current + i, spawnArea[/*Random.Range(0, spawnArea.Length)*/4], curPopped); bool spawnedCorrectly = trashAreaHandler.Spawn(standard + indexForm, spawnArea[indexSpawnArea], curPopped, Random.Range(100, 160)); if (spawnedCorrectly) { StartCoroutine(GrowToSize(curPopped)); spawnable_curList.RemoveAt(lastPos); spawned_curList.Add(curPopped); ret = curPopped; LevelBalancing.SetTrashValue(curPopped.personalTrashValue); } else if (!spawnedCorrectly) { curPopped.gameObject.SetActive(false); } return(ret); }