Exemplo n.º 1
0
    public bool Fire(Vector3 position, Vector3 direction, AudioSource audioSource)
    {
        //We need to check for all of the legality of shooting before we try to actually fire
        if (currentlyEquipped)
        {
            if (!CanFire)
            {
                //Debug.LogError("Cant Fire");
                return(false);
            }

            if (HasAmmo() == false)
            {
                Debug.LogError("No Ammo");
                return(false);
            }

            currentlyEquipped.Fire(position, direction.normalized, audioSource);
            SpendAmmo();
            lastFireTime = Time.time;
            UpdateUI();

            //Trying to prevent the double muzzle flash
            if (!flashing)
            {
                StartCoroutine(MuzzleFlashCoroutine(currentlyEquipped.muzzleFlashTime));
            }
        }

        return(true);
    }
Exemplo n.º 2
0
    public void AnimationShoot(int amount)
    {
        Vector3 fireDirection = lastTargetPosition - muzzlePointTransform.position;

        fireDirection += transform.right * Random.Range(-accuracy, accuracy);
        fireDirection += transform.up * Random.Range(-accuracy, accuracy);

        equippedGun.Fire(muzzlePointTransform.position, fireDirection, audioSource);
        Debug.DrawRay(muzzlePointTransform.position, fireDirection, Color.red, 2f);

        GameObject trail;

        //Creates a bullet train to add better visuals for where the AI is shooting
        if (!RecycleManager.TryGetItem("BulletTrail", out trail))
        {
            trail = Instantiate(fireLinePrefab);
        }

        trail.GetComponent <BulletTrail>().Init(muzzlePointTransform.position, fireDirection);
    }