2023-04-11 19:55:24 -07:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2023-05-06 22:09:15 -07:00
|
|
|
public class ProjectileEnemy : MonoBehaviour
|
|
|
|
{
|
2023-04-11 19:55:24 -07:00
|
|
|
|
|
|
|
[SerializeField] GameObject projectile;
|
|
|
|
[SerializeField] GameObject firePoint;
|
2023-05-06 22:09:15 -07:00
|
|
|
[SerializeField][Range(0.1f, 3f)] float fireSpeed;
|
2023-04-30 13:34:02 -07:00
|
|
|
[SerializeField] float projectileSpeed;
|
2023-04-11 19:55:24 -07:00
|
|
|
|
|
|
|
// Start is called before the first frame update
|
2023-05-06 22:09:15 -07:00
|
|
|
void Start()
|
|
|
|
{
|
2023-04-11 19:55:24 -07:00
|
|
|
StartCoroutine(Fire());
|
|
|
|
}
|
|
|
|
|
2023-05-06 22:09:15 -07:00
|
|
|
IEnumerator Fire()
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(1 / fireSpeed);
|
2023-04-11 19:55:24 -07:00
|
|
|
GameObject newProjectile = Instantiate(projectile, firePoint.transform.position, firePoint.transform.rotation);
|
2023-04-30 13:34:02 -07:00
|
|
|
newProjectile.GetComponent<Rigidbody2D>().AddRelativeForce(new Vector2(projectileSpeed, 0));
|
2023-05-06 22:09:15 -07:00
|
|
|
newProjectile.transform.Rotate(new Vector3(0, 0, -90));
|
2023-04-11 19:55:24 -07:00
|
|
|
StartCoroutine(Fire());
|
|
|
|
}
|
|
|
|
}
|