Advertisement
LeeMace

Simple Spawn Manger

Dec 2nd, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SpawnManager : MonoBehaviour
  6. {
  7.     public GameObject[] obstaclePrefab;
  8.     private Vector3 spawnPos = new Vector3 (25, 0, 0);
  9.     private float startDelay = 2;
  10.     private float repeatRate = 2;
  11.     private PlayerController playerController;
  12.        
  13.         // Start is called before the first frame update
  14.     void Start() //repeats spawn so that we get mulptiple objects spawned in the time we set.
  15.     {
  16.        InvokeRepeating("SpawnObstacle", startDelay, repeatRate);
  17.         playerController = GameObject.Find("Player").GetComponent<PlayerController>();
  18.     }
  19.     void SpawnObstacle() //spawns obstacle in position and at correct angle until game over
  20.     {
  21.        if (playerController.gameOver == false)
  22.         {
  23.             int obstacleIndex = Random.Range(0, obstaclePrefab.Length);
  24.             Instantiate(obstaclePrefab[obstacleIndex], spawnPos, obstaclePrefab[obstacleIndex].transform.rotation);
  25.  
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement