Advertisement
LeeMace

Instantiate cube list at spawn points list

Jun 26th, 2023
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | Gaming | 0 0
  1. public class Manager : MonoBehaviour
  2. {
  3.     [SerializeField] GameObject[] spawnpoints;
  4.     [SerializeField] BaseCube[] cubePrefabs;
  5.     List<BaseCube> cubes;
  6.  
  7.     void Start()
  8.     {
  9.         InstansiateCubes();
  10.     }
  11.  
  12.     void Update()
  13.     {
  14.         MakeItHappen();
  15.     }
  16. // instantiates and puts cubes into list then spawns them at list of spawn points
  17.     public void InstansiateCubes() {
  18.  
  19.         cubes = new List<BaseCube>();
  20.         for (int i = 0; i < spawnpoints.Length; i++) {
  21.             BaseCube cube = Instantiate(cubePrefabs[i]);
  22.             cubes.Add(cube);
  23.             cubes[i].transform.position = spawnpoints[i].transform.position;
  24.         }
  25.     }
  26. // calls dostuff from base class
  27.     public void MakeItHappen() {
  28.  
  29.         if (Input.GetKey(KeyCode.Space)) {
  30.  
  31.             foreach (BaseCube cube in cubes) {
  32.  
  33.                 cube.DoStuff();
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement