Example #1
0
    protected virtual void OnShotFired()
    {
        weaponAudioManager.Play("Fire");
        if (anim.runtimeAnimatorController != null)
        {
            anim.SetTrigger("Single_Shot");
        }
        if (onShootEffect != null)
        {
            Destroy(Instantiate(onShootEffect, barrelEnd.position, barrelEnd.rotation), onShootEffectLifetime);
        }

        if (casingPrefab != null)
        {
            GameObject newShell = Instantiate(casingPrefab, casingPoint.position, casingPoint.rotation);
            newShell.GetComponent <Rigidbody>().AddForce(casingPoint.forward * Random.Range(casingForceMultiplier * .8f, casingForceMultiplier * 1.2f));
            if (casingLifeTime > 0)
            {
                Destroy(newShell, casingLifeTime);
            }
            weaponAudioManager.Play("Casing");
        }

        shotsFired++;
    }
Example #2
0
    void Shoot()
    {
        muzzleFlash.Play();
        anim.SetTrigger("FiringTrigger");
        weaponAudioManager.Play(soundName);
        //currentAmmo--;
        magazine--;

        RaycastHit hit;

        if (Physics.Raycast(raycastOrigin.position, raycastOrigin.forward, out hit))
        {
            GameObject  hitImpactEffect;
            IDamageable target;

            if (hit.transform.TryGetComponent <IDamageable>(out target))
            {
                bool killed = target.Damage(damage);
                UnityEngine.Debug.Log(hit.transform.name + " damaged for: " + damage);
                if (killed)
                {
                    MatchManager.i.AddFrag(transform.parent.parent.name);
                }
            }

            // Different impact effect for enemy and environment;
            if (hit.transform.tag == "Enemy" || hit.transform.tag == "Player")
            {
                hitImpactEffect = characterImpactEffect;
            }
            else
            {
                hitImpactEffect = impactEffect;
            }
            GameObject impactGO = Instantiate(hitImpactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactGO, 1f);
        }
    }