public void MakeOneShot(RectTransform center, BulletCache cache) { float targetPoint; if (times % 2 == 0) { var half = times / 2; targetPoint = center.anchoredPosition.x - (distanceInterval / 2 + distanceInterval * (half - 1)); } else { var half = (times - 1) / 2; targetPoint = center.anchoredPosition.x - (distanceInterval * half); } var bulletList = new List <Bullet>(); for (int i = 0; i < times; ++i) { var bullet = cache.GetBullet(); bullet.SwitchBulletImage(false); bullet.BulletRect.anchoredPosition = new Vector2(targetPoint, center.anchoredPosition.y + centerDistance); targetPoint += distanceInterval; bulletList.Add(bullet); } foreach (var bullet in bulletList) { bullet.BulletRigidbody2D.velocity = Vector2.up * speed; } }
public IEnumerator MakeUzumaki(RectTransform center, BulletCache cache, int times, Action action) { for (int i = 0; i < times; i++) { var deg = 0f; while (deg < fullAngle) { var rad = deg * Mathf.Deg2Rad; var cos = Mathf.Cos(rad); var sin = Mathf.Sin(rad); var bullet = cache.GetBullet(); bullet.SwitchBulletImage(true); bullet.BulletRect.anchoredPosition = new Vector2(center.anchoredPosition.x + radius * cos, center.anchoredPosition.y + radius * sin); bullet.BulletRigidbody2D.velocity = (bullet.BulletRect.anchoredPosition - center.anchoredPosition).normalized * speed; deg += degInterval; yield return(new WaitForSeconds(makeInterval)); } } action?.Invoke(); }