Seascape/Assets/Scripts/BulletScript.cs

49 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using Unity.VisualScripting;
using UnityEngine;
public class BulletScript : MonoBehaviour
{
public PlayerScript PlayerScript;
[SerializeField] public int speed = 3;
[SerializeField] public float maxY = 12f;
[SerializeField] public float BulletLiveTime;
[SerializeField] public float BulletLive;
[SerializeField] private int maxSpawns = 4;
[SerializeField] private float spawnTimer = 5;
[SerializeField] private float counter = 0;
[SerializeField] private int spawnCounter = 0;
public Vector3 direction = Vector3.up;
public GameObject WaveBullet;
public Transform firePoint;
public Rigidbody rb;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (spawnCounter < maxSpawns)
{
counter += Time.deltaTime;
if (counter >= spawnTimer)
{
Shoot();
counter = 0;
}
}
}
void Shoot()
{
Instantiate(WaveBullet, firePoint.position, firePoint.rotation);
rb.velocity = transform.up * speed * Time.deltaTime;
}
}
}