private IEnumerator ShotCoroutine() { if (m_bulletNum <= 0 || m_bulletSpeed <= 0f || m_wayNum <= 0 || m_spiralWayNum <= 0) { Debug.LogWarning("Cannot shot because BulletNum or BulletSpeed or WayNum or SpiralWayNum is not set."); yield break; } if (m_shooting) { yield break; } m_shooting = true; float spiralWayShiftAngle = 360f / m_spiralWayNum; int wayIndex = 0; int spiralWayIndex = 0; for (int i = 0; i < m_bulletNum; i++) { if (m_wayNum <= wayIndex) { wayIndex = 0; spiralWayIndex++; if (m_spiralWayNum <= spiralWayIndex) { spiralWayIndex = 0; if (0f < m_nextLineDelay) { FiredShot(); yield return(new WaitForSeconds(m_nextLineDelay)); } } } var bullet = GetBullet(transform.position); if (bullet == null) { break; } float centerAngle = m_startAngle + (spiralWayShiftAngle * spiralWayIndex) + (m_shiftAngle * Mathf.Floor(i / m_wayNum)); float baseAngle = m_wayNum % 2 == 0 ? centerAngle - (m_betweenAngle / 2f) : centerAngle; float angle = Utils2D.GetShiftedAngle(wayIndex, baseAngle, m_betweenAngle); ShotBullet(bullet, m_bulletSpeed, angle); wayIndex++; } FiredShot(); FinishedShot(); yield break; }
private IEnumerator ShotCoroutine() { if (m_bulletNum <= 0 || m_bulletSpeed <= 0f || m_wayNum <= 0) { Debug.LogWarning("Cannot shot because BulletNum or BulletSpeed or WayNum is not set."); yield break; } if (m_shooting) { yield break; } m_shooting = true; int wayIndex = 0; float bulletSpeed = m_bulletSpeed; float shiftAngle = 0f; for (int i = 0; i < m_bulletNum; i++) { if (m_wayNum <= wayIndex) { wayIndex = 0; if (0f < m_nextLineDelay) { FiredShot(); yield return(new WaitForSeconds(m_nextLineDelay)); } bulletSpeed += m_diffSpeed; shiftAngle += m_shiftAngle; } var bullet = GetBullet(transform.position); if (bullet == null) { break; } float baseAngle = m_wayNum % 2 == 0 ? m_centerAngle - (m_betweenAngle / 2f) : m_centerAngle; float angle = Utils2D.GetShiftedAngle(wayIndex, baseAngle, m_betweenAngle) + shiftAngle; ShotBullet(bullet, bulletSpeed, angle); wayIndex++; } FiredShot(); FinishedShot(); yield break; }
public override void Shot() { if (m_bulletNum <= 0 || m_bulletSpeed <= 0f || m_wayNum <= 0) { Debug.LogWarning("Cannot shot because BulletNum or BulletSpeed or WayNum is not set."); return; } if (m_shooting) { return; } m_shooting = true; int wayIndex = 0; float bulletSpeed = m_bulletSpeed; for (int i = 0; i < m_bulletNum; i++) { if (m_wayNum <= wayIndex) { wayIndex = 0; bulletSpeed -= m_diffSpeed; while (bulletSpeed <= 0) { bulletSpeed += Mathf.Abs(m_diffSpeed); } } var bullet = GetBullet(transform.position); if (bullet == null) { break; } float baseAngle = m_wayNum % 2 == 0 ? m_centerAngle - (m_betweenAngle / 2f) : m_centerAngle; float angle = Utils2D.GetShiftedAngle(wayIndex, baseAngle, m_betweenAngle); ShotBullet(bullet, bulletSpeed, angle); wayIndex++; } FiredShot(); FinishedShot(); }