initial commit
This commit is contained in:
35
Assets/Scripts/Lesson_2/CubeSpawner.cs
Normal file
35
Assets/Scripts/Lesson_2/CubeSpawner.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user