//gets next trash spawn type public ThrowablesScriptableObject NextRandomTrashType() { ThrowablesScriptableObject pickedType = trashDatas[Random.Range(0, trashDatas.Length)]; if (trashDatas.Length > 2) { while (pickedType == null || pickedType == lastTrash1 || pickedType == lastTrash2) { pickedType = trashDatas[Random.Range(0, trashDatas.Length)]; } lastTrash2 = lastTrash1; lastTrash1 = pickedType; } return(pickedType); }
//spawns trash at location public void SpawnTrash(Vector3 location, ThrowablesScriptableObject trashType) { if (trashNumber < 9) { //not the drop Quaternion qua = Quaternion.Euler(Random.Range(-180f, 180f), Random.Range(-180f, 180f), Random.Range(-180f, 180f)); GameObject spawnedTrash = Instantiate(throwablePrefab, location, qua); spawnedTrash.GetComponentInChildren <Throwable>().throwableData = trashType; spawnedTrash.GetComponentInChildren <Throwable>().LoadData(); trashNumber++; } else if (trashNumber == 9) { foreach (Transform child in pileDrop.transform) { Quaternion qua = Quaternion.Euler(Random.Range(-180f, 180f), Random.Range(-180f, 180f), Random.Range(-180f, 180f)); GameObject spawnedTrash = Instantiate(throwablePrefab, location + child.transform.position, qua); spawnedTrash.GetComponentInChildren <Throwable>().throwableData = NextRandomTrashType(); spawnedTrash.GetComponentInChildren <Throwable>().LoadData(); trashNumber++; } } else if (Random.value > chanceForPileDrop) { //not the drop Quaternion qua = Quaternion.Euler(Random.Range(-180f, 180f), Random.Range(-180f, 180f), Random.Range(-180f, 180f)); GameObject spawnedTrash = Instantiate(throwablePrefab, location, qua); spawnedTrash.GetComponentInChildren <Throwable>().throwableData = trashType; spawnedTrash.GetComponentInChildren <Throwable>().LoadData(); trashNumber++; } else { foreach (Transform child in pileDrop.transform) { Quaternion qua = Quaternion.Euler(Random.Range(-180f, 180f), Random.Range(-180f, 180f), Random.Range(-180f, 180f)); GameObject spawnedTrash = Instantiate(throwablePrefab, location + child.transform.position, qua); spawnedTrash.GetComponentInChildren <Throwable>().throwableData = NextRandomTrashType(); spawnedTrash.GetComponentInChildren <Throwable>().LoadData(); trashNumber++; } } }