using UnityEngine; using System.Collections.Generic; using System.Collections; public class Player_FireAttack : MonoBehaviour { private float nextFire; public float cooldown; public int volleySize; public float launchPower; public float attackSpeed; public Transform shotSpawn; public GameObject fireBall; private Rigidbody2D body; private bool _ready; private bool _activated; private void Start() { nextFire = 0; _ready = true; _activated = false; } private void Update() { _ready = Time.time > nextFire; if (!_activated) return; print("Fire_Attack"); nextFire = Time.time + cooldown; StartCoroutine(fire()); _activated = false; //if (Input.GetButtonDown("Fire1") && Time.time > nextFire) //{ // nextFire = Time.time + Cooldown; // StartCoroutine(fire()); //} } public bool Attack() { if (_ready) { _activated = true; } return _ready; } IEnumerator fire() { for (int i = 0; i < volleySize; i++) { GameObject projectile = Instantiate(fireBall, shotSpawn.position, shotSpawn.rotation); Vector3 direction = shotSpawn.position - transform.position; projectile.GetComponent().velocity = direction * launchPower; yield return new WaitForSeconds(attackSpeed); } } }