Hello, I am kind of a beginer in Unity and I have the following problem: I am trying to make that every FRAME my spawner spaws faster. Now, I realized that my code doesn´t have a variable with the speed that spawns, no, that would be simple, but instead I have a timer that goes down, spawns a prefabs , resets the timer and deletes the clone of the prefab.
If you can add a variable, a while code or anything that can help, or a link to a post and stuff like that, I would really appreciate that. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawn : MonoBehaviour
{
public GameObject bulletPrefab;
GameObject bulletPrefabClone;
public Transform spawnPoint;
public float Timer = 2f;
public GameObject badPrefab;
GameObject badPrefabClone;
void Start()
{
}
void Update()
{
Timer -= Time.deltaTime;
if (Timer <= 0f)
{
bulletPrefabClone = Instantiate(bulletPrefab, new Vector3(Random.Range(-9, 9), 5f, 0f), transform.rotation) as GameObject;
Timer = 2f;
Destroy(bulletPrefabClone, 2.1f);
badPrefabClone = Instantiate(badPrefab, new Vector3(Random.Range(-9, 9), 5f, 0f), transform.rotation) as GameObject;
Timer = 2f;
Destroy(badPrefabClone, 2.1f);
}
}
}
NOTE: English isn´t my native language.