BossAimedWayAttack.cs

Anonymous
csharp
08/14/2026 4:09 PM
2.5 KB
1
Indexable
using UnityEngine;

public class BossAimedNWayAttack : MonoBehaviour
{
    [Header("Aimed N-Way Settings")]
    public GameObject bulletPrefab;
    [Tooltip("���ˊԊu�i�b�j")]
    public float fireInterval = 1.5f;
    [Tooltip("���˂���e�̐��iway���F����������߁j")]
    public int wayCount = 5;
    [Tooltip("�e���m�̊p�x�̌��ԁi�x�j")]
    public float angleStep = 10f;

    private float timer;

    void Update()
    {
        timer += Time.deltaTime;
        if (timer >= fireInterval)
        {
            FireAimedNWay();
            timer = 0f;
        }
    }

    void FireAimedNWay()
    {
        if (bulletPrefab == null) return;

        // �V�[����̃v���C���[��T��
        GameObject player = GameObject.FindWithTag("Player");
        if (player == null) return;

        // �v���C���[�ւ̕����x�N�g�������p�x�i�x�j���v�Z
        Vector2 dirToPlayer = (player.transform.position - transform.position).normalized;
        float baseAngle = Mathf.Atan2(dirToPlayer.y, dirToPlayer.x) * Mathf.Rad2Deg;

        // ���ɍL����悤�ɊJ�n�p�x�𒲐�
        float startAngle = baseAngle - (angleStep * (wayCount - 1) / 2f);

        for (int i = 0; i < wayCount; i++)
        {
            float currentAngle = startAngle + (angleStep * i);
            float rad = currentAngle * Mathf.Deg2Rad;
            Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad));

            GameObject bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity);

            var bulletScript = bullet.GetComponent<EnemyStraightBullet>();
            if (bulletScript != null)
            {
                bulletScript.SetDirection(dir);
            }
        }
    }
}
Editor is loading...
Leave a Comment