Pong-Pong/Assets/Scripts/Spawners/GunSpawner.cs
Gerard Gascón 16da8e4dde init
2025-04-24 17:09:22 +02:00

29 lines
1,008 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GunSpawner : MonoBehaviour{
public string[] ObjectToSpawn;
Vector2 whereToSpawn;
GameController gameController;
float nextSpawn;
float spawnRate;
void Start(){
gameController = FindObjectOfType<GameController>();
spawnRate = gameController.actualGunSpawnRate;
}
// Update is called once per frame
void Update(){
spawnRate = gameController.actualGunSpawnRate;
if (Time.time > nextSpawn){
nextSpawn = Time.time + spawnRate;
float xPos = Random.Range(gameController.minSpawnPos.x, gameController.maxSpawnPos.x);
float yPos = Random.Range(gameController.minSpawnPos.y, gameController.maxSpawnPos.y);
whereToSpawn = new Vector2(xPos, yPos);
ObjectPooler.Instance.SpawnFromPool(ObjectToSpawn[Mathf.RoundToInt(Random.Range(0f, 5f))], whereToSpawn, Quaternion.identity);
}
}
}