Seascape/Assets/Scripts/WaveSpawn.cs

56 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaveSpawn : MonoBehaviour
{
public PlayerScript playerScript;
//private Vector3 direction = Vector3.up;
[SerializeField] private int maxSpawns = 5;
[SerializeField] private int currentSpawns = 0;
[SerializeField] private float spawnCooldown = 1;
[SerializeField] private float spawnCoolCounter = 0;
public GameObject WaveBullet;
public Transform firePoint;
// Update is called once per frame
void Update()
{
spawnCoolCounter += Time.deltaTime;
//Reguliuert den CurrentSpawn Count
if (spawnCoolCounter > spawnCooldown)
{
if (currentSpawns >= 1)
{
currentSpawns--;
}
spawnCoolCounter = 0;
}
if (Input.GetButtonDown("Fire1"))
{
Debug.Log("Ich versuche zu schießen");
//Prüft, ob das Limit noch nicht überschreitet ist
if (currentSpawns < maxSpawns)
{
//Debug.Log("Darf was spawnen");
Spawn();
}
}
void Spawn()
{
Instantiate(WaveBullet, firePoint.position, firePoint.rotation);
Debug.Log("Bullet spawnt");
currentSpawns++;
}
}
}