Advertisement
SizilStank

Untitled

Sep 26th, 2022
1,594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5.  
  6. public class SpawnOnWayPoints : MonoBehaviour
  7. {
  8.  
  9.     //Array of points in the game for the gameobject to spawn on
  10.     [SerializeField] private Transform[] _spawnPoints;
  11.     //Array of gameobjects that will be spawned on the spawn points
  12.     [SerializeField] private GameObject _spawnObjects;
  13.    
  14.     public Transform[] Transform => _spawnPoints;
  15.  
  16.     // Start is called before the first frame update
  17.     void Start()
  18.     {
  19.         InstantiateOnWayPoints();      
  20.     }
  21.  
  22.  
  23.     private void InstantiateOnWayPoints()
  24.     {   //for loop iterating through the length of the spawn points and adding one
  25.         for (int i = 0; i < _spawnPoints.Length; i++)
  26.         {   //setting the position of the spawn points position in the game
  27.             transform.position = _spawnPoints[i].transform.position;
  28.             //spawning the gameobjects to their respective spawn point in the game
  29.             GameObject spawnObjects = Instantiate(_spawnObjects, transform.position, Quaternion.identity);//what is ... for?
  30.         }
  31.        
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement