private void Shoot(int n) { if (n < 1) { n = 1; } if (n == 1) { GameObject newRocket = Instantiate(rocket, transform.position + Vector3.down * 1.2f, Quaternion.identity); EnemyProjectileBehavior e = newRocket.GetComponent <EnemyProjectileBehavior>(); foreach (Transform child in newRocket.transform) { SpriteRenderer s = child.GetComponent <SpriteRenderer>(); s.enabled = false; } e.ChangeDirection(Vector3.down); } }
private void Shoot(int n) { if (n < 1) { n = 1; } if (n == 1) { Vector2 toPlayer = player.transform.position - transform.position; // Get Vec2 direction to player GameObject newRocket = Instantiate(rocket, transform.position, Quaternion.identity); EnemyProjectileBehavior e = newRocket.GetComponent <EnemyProjectileBehavior>(); e.ChangeDirection(toPlayer); } else { float realProjectileRotationDegree; if (n > 7) { realProjectileRotationDegree = maxFanShootingDegree / (n - 1); } else { realProjectileRotationDegree = projectileRotationDegree; } if (n % 2 == 0) { for (int i = 0; i < n / 2; ++i) { Vector2 toPlayer = player.transform.position - transform.position; // Get Vec2 direction to player GameObject newRocket1 = Instantiate(rocket, transform.position, Quaternion.identity); EnemyProjectileBehavior e1 = newRocket1.GetComponent <EnemyProjectileBehavior>(); GameObject newRocket2 = Instantiate(rocket, transform.position, Quaternion.identity); EnemyProjectileBehavior e2 = newRocket2.GetComponent <EnemyProjectileBehavior>(); float rotationDeg = ((float)i + 0.5f) * realProjectileRotationDegree; Vector2 left = Quaternion.AngleAxis(rotationDeg, Vector3.forward) * toPlayer; Vector2 right = Quaternion.AngleAxis(-rotationDeg, Vector3.forward) * toPlayer; Debug.DrawLine(transform.position, new Vector3(transform.position.x + left.x, transform.position.y + left.y, 0.0f)); e1.ChangeDirection(left); e2.ChangeDirection(right); } } else { Vector2 toPlayer = player.transform.position - transform.position; // Get Vec2 direction to player for (int i = 0; i < n / 2; ++i) { GameObject newRocket1 = Instantiate(rocket, transform.position, Quaternion.identity); EnemyProjectileBehavior e1 = newRocket1.GetComponent <EnemyProjectileBehavior>(); GameObject newRocket2 = Instantiate(rocket, transform.position, Quaternion.identity); EnemyProjectileBehavior e2 = newRocket2.GetComponent <EnemyProjectileBehavior>(); float rotationDeg = ((float)i + 1.0f) * realProjectileRotationDegree; Vector2 left = Quaternion.AngleAxis(rotationDeg, Vector3.forward) * toPlayer; Vector2 right = Quaternion.AngleAxis(-rotationDeg, Vector3.forward) * toPlayer; Debug.DrawLine(transform.position, new Vector3(transform.position.x + left.x, transform.position.y + left.y, 0.0f)); e1.ChangeDirection(left); e2.ChangeDirection(right); } GameObject newRocket3 = Instantiate(rocket, transform.position, Quaternion.identity); EnemyProjectileBehavior e3 = newRocket3.GetComponent <EnemyProjectileBehavior>(); e3.ChangeDirection(toPlayer); } } }