36 lines
995 B
C#
36 lines
995 B
C#
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class CubeSpawner : MonoBehaviour
|
|
{
|
|
public WaterLevelController waterLevelController;
|
|
public GameObject[] cubesPrefabs;
|
|
|
|
public int minScale = 1;
|
|
public int maxScale = 5;
|
|
|
|
private void Start()
|
|
{
|
|
for (int i = 0; i < cubesPrefabs.Length; i++)
|
|
{
|
|
cubesPrefabs[i].transform.localScale = new Vector3(Random.Range(minScale, maxScale), Random.Range(minScale, maxScale), Random.Range(minScale, maxScale));
|
|
}
|
|
}
|
|
|
|
public void SpawnNewCube(int cubeId)
|
|
{
|
|
waterLevelController.currentCubeMass = 0f;
|
|
waterLevelController.currentCubeVolume = 0f;
|
|
|
|
cubeId = cubeId - 1;
|
|
while (transform.childCount > 0)
|
|
{
|
|
DestroyImmediate(transform.GetChild(0).gameObject);
|
|
}
|
|
|
|
GameObject newCube = Instantiate(cubesPrefabs[cubeId]);
|
|
newCube.transform.SetParent(transform);
|
|
newCube.transform.localPosition = Vector3.zero;
|
|
}
|
|
}
|