Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SpawnManager : MonoBehaviour
- {
- public GameObject[] obstaclePrefab;
- private Vector3 spawnPos = new Vector3 (25, 0, 0);
- private float startDelay = 2;
- private float repeatRate = 2;
- private PlayerController playerController;
- // Start is called before the first frame update
- void Start() //repeats spawn so that we get mulptiple objects spawned in the time we set.
- {
- InvokeRepeating("SpawnObstacle", startDelay, repeatRate);
- playerController = GameObject.Find("Player").GetComponent<PlayerController>();
- }
- void SpawnObstacle() //spawns obstacle in position and at correct angle until game over
- {
- if (playerController.gameOver == false)
- {
- int obstacleIndex = Random.Range(0, obstaclePrefab.Length);
- Instantiate(obstaclePrefab[obstacleIndex], spawnPos, obstaclePrefab[obstacleIndex].transform.rotation);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement