Exemplo n.º 1
0
    public void Fire(bool checkCanFire = true)
    {
        if (checkCanFire && canFireAgain is false)
        {
            return;
        }
        HaltFire();

        source.Play();
        var newObj     = Instantiate(projectilePrefab, ejectionPoint.transform.position, this.transform.rotation, BulletCollector.Instance.transform);
        var projectile = newObj.GetComponent <Projectile>();

        projectile.MegaBullet = MegaFire;
        if (sourceColliders.Length != 0)
        {
            foreach (var collider in sourceColliders)
            {
                projectile.IgnoreCollision(collider);
            }
        }
        if (SuperMegaFire && extraPizzazz != null)
        {
            extraPizzazz.Play();
            projectile.FlightSpeed  *= 2;
            projectile.IgnoreShields = true;
            projectile.Damage       *= 3;
        }
        else if (MegaFire)
        {
            projectile.FlightSpeed = (int)(projectile.FlightSpeed * 1.5f);
        }

        if (movementSource != null)
        {
            var   sourceVelocity = movementSource.GetVelocity();
            float deltaSpeed     = Vector3.Dot(transform.forward, sourceVelocity);
            if (deltaSpeed > 0)
            {
                projectile.FlightSpeed += Mathf.RoundToInt(deltaSpeed);
            }
        }

        if (LoopFire)
        {
            fireId = LeanTween.delayedCall(RefireRate, () => Fire(false)).id;
        }
        canFireAgain = false;
    }