gimm-platformer-project/Assets/Scripts/tetrominoSpawnManager.cs

59 lines
1.6 KiB
C#
Raw Normal View History

2021-10-01 15:30:01 -06:00
using UnityEngine;
2021-10-07 13:56:22 -06:00
using Random = UnityEngine.Random;
2021-10-01 15:30:01 -06:00
public class tetrominoSpawnManager : MonoBehaviour
2021-10-01 15:30:01 -06:00
{
public Vector3 spawnPoint;
public GameObject tetrominoSquare;
2021-10-07 13:56:22 -06:00
public GameObject tetrominoLine;
public GameObject tetrominoL;
public GameObject tetrominoR;
public GameObject tetrominoS;
public GameObject tetrominoT;
2021-10-14 12:56:24 -06:00
public GameObject tetrominoZ;
2021-10-07 13:56:22 -06:00
private int nextTetromino = 0;
2021-10-21 12:14:34 -06:00
private GameObject nextTetrominoObject;
2021-10-01 15:30:01 -06:00
// Start is called before the first frame update
void Start()
{
spawnTetromino();
2021-10-01 15:30:01 -06:00
}
public void spawnTetromino()
2021-10-01 15:30:01 -06:00
{
2021-10-14 12:56:24 -06:00
nextTetromino = Random.Range(1, 7);
2021-10-07 13:56:22 -06:00
switch (nextTetromino)
{
case 0: //Square
2021-10-21 12:14:34 -06:00
nextTetrominoObject = tetrominoSquare;
2021-10-07 13:56:22 -06:00
break;
case 1: //Line
2021-10-21 12:14:34 -06:00
nextTetrominoObject = tetrominoLine;
2021-10-07 13:56:22 -06:00
break;
case 2: //T-piece
2021-10-21 12:14:34 -06:00
nextTetrominoObject = tetrominoT;
break;
case 3: //L-piece
nextTetrominoObject = tetrominoL;
break;
case 4: //R-piece
nextTetrominoObject = tetrominoR;
break;
case 5: //S-piece
nextTetrominoObject = tetrominoS;
break;
case 6: //Z-piece
nextTetrominoObject = tetrominoZ;
2021-10-07 13:56:22 -06:00
break;
2021-10-14 12:56:24 -06:00
default: //if it's not a piece I have a prefab for yet, default to square
2021-10-21 12:14:34 -06:00
nextTetrominoObject = tetrominoSquare;
2021-10-07 13:56:22 -06:00
break;
}
2021-10-21 12:14:34 -06:00
Instantiate(nextTetrominoObject, spawnPoint, Quaternion.identity);
2021-10-01 15:30:01 -06:00
}
}