コード例 #1
0
    private IEnumerator ShootInIntervals()
    {
        // move at random intervals
        while (_shooting)
        {
            _directionToFire = _playerTransform.position - transform.position;

            float angle = Mathf.Atan2(_directionToFire.y, _directionToFire.x) * Mathf.Rad2Deg;
            _enemyWeapon.SetNewWeaponRotation(angle);

            float fireWaitTime = Random.Range(_minAimInterval, _maxAimInterval);
            bool  fire         = PlayerInView();

            yield return(new WaitForSeconds(fireWaitTime));

            if (_setNoticeSprite && PlayerInView())
            {
                _noticeGameobject.SetActive(true);
                yield return(new WaitForSeconds(_noticeTime));

                _noticeGameobject.SetActive(false);
            }

            for (int i = 0; i < _bulletsToFire; i++)
            {
                if (fire)
                {
                    _enemyWeapon.FireWeapon();
                }
                yield return(new WaitForSeconds(_enemyWeapon.GetFireDelay()));
            }

            yield return(new WaitForSeconds(Random.Range(_minFireInterval, _maxFireInterval)));
        }
    }