static IEnumerator ShotAndReturnTransverselyLineBullets(GameObject bulletPrefab, Vector3 position, Quaternion rotation, int bulletsNumber, float angle, float spownTime) { List <GameObject> bullets = new List <GameObject>(); float length = Mathf.Tan(angle * Mathf.Deg2Rad / 2) * 2; //数字横行的长度 float eulerZ = rotation.eulerAngles.z; float startTime = Time.time; for (int i = 0; i < bulletsNumber; i++) { float currentX = length / (bulletsNumber - 1) * i - length / 2; Quaternion currentRotation = BarrageBase.GetAimRotation(Vector2.zero, new Vector2(currentX, 1)); currentRotation.eulerAngles = currentRotation.eulerAngles + new Vector3(0, 0, eulerZ); GameObject bullet = GetInactiveBullet(bulletPrefab, position, currentRotation); bullets.Add(bullet); BulletMoveUp move = bullet.GetComponent <BulletMoveUp>(); move.speed = move.speed * Mathf.Sqrt(1 + currentX * currentX); //因为到中心点的距离是1,那么所有点的速度比例就和距离相同,直接乘上就行 float expectedTime = spownTime / bulletsNumber * i; float elapsedTime = Time.time - startTime; if (expectedTime > elapsedTime) { yield return(new WaitForSeconds(expectedTime - elapsedTime)); } } yield return(bullets.ToArray()); }
void DoShot() { Vector2 shotPoint = new Vector2(Random.Range(-300, 300), Random.Range(0, 500)); Quaternion rotateToPlayer = BarrageBase.GetAimRotation(shotPoint, _playerTransform.position); BarrageLauncher.ShotRing(_bullet, shotPoint, rotateToPlayer, 18); //BarrageLauncher.ShotABullet(_bullet, shotPoint, rotateToPlayer); //BarrageLauncher.ShotFanShaped(_bullet, shotPoint, rotateToPlayer, 9, 60); //BarrageLauncher.ShotTransverselyLine(_bullet, shotPoint, rotateToPlayer, 17, 60); //BarrageLauncher.ShotPane(_bullet, shotPoint, rotateToPlayer, 7); //BarrageLauncher.ShotRingToCenter(_bullet, _playerTransform.position, Quaternion.identity, 8, 400); UpdateNextShot(); }
private void Update() { if (Time.time < _startAimTime) { return; } if (_playerTransform != null) { float rate = Mathf.Min(1, Mathf.InverseLerp(_startAimTime, _endAimTime, Time.time)); Quaternion targetRotation = BarrageBase.GetAimRotation(_bulletMove.transform.position, _playerTransform.position); _bulletMove.rotation = Quaternion.Lerp(_bulletMove.rotation, targetRotation, rate); } else { _playerTransform = BarrageBase.GetPlayerTransform(); } if (Time.time > _endAimTime) { enabled = false; } }