Пример #1
0
    private void ShootBullet()
    {
        BaseBullet bullet = bulletPool.GetOrCreate <BaseBullet>();

        bullet.InitializeBullet();
        bullet.SetBulletPos(this.transform.position);
    }
Пример #2
0
    /// <summary>
    /// Shoots the bullet.
    /// Will return whether bullet is successfully shot.
    /// </summary>
    /// <returns><c>true</c>, if bullet was shot, <c>false</c> otherwise.</returns>
    public bool ShootBullet()
    {
        RunBulletShootTimer(bulletShootPeriod);

        bool isBulletShot = false;

        if (this.bulletTriggerType != BulletTriggerType.Auto)
        {
            // If timer is still active (still counting down), cannot shoot yet.
            if (bulletShootTimer.IsTimerActive())
            {
                return(isBulletShot);
            }
        }

        for (int i = 0; i < unitBulletShootCount; i++)
        {
            // In case pool count exceeds max, it may return null.
            Bullet bullet = bulletPool.GetOrCreate <Bullet>();
            if (bullet == null)
            {
                continue;
            }

            // Update bullet status.
            bullet.UpdateBulletInfo(this.bulletType);
            bullet.ApplyBulletInfo();

            bullet.gameObject.SetActive(true);
            if (this.aimType == BulletAimType.FixDir)
            {
                bullet.bulletInfo.SetBulletVelocity(startPos[i], destPos[i]);
            }
            else
            {
                bullet.bulletInfo.SetBulletVelocity(startPos[i], targets[i].transform.position);
            }
            isBulletShot = true;
        }
        return(isBulletShot);
    }