Ejemplo n.º 1
0
    private void FireBullet()
    {
        if (ammoCount <= 0)
        {
            return;
        }

        ammoCount--;

        foreach (var particle in muzzleFlash)
        {
            particle.Emit(1);
        }

        ray.origin    = raycastOrigin.position;
        ray.direction = raycastDestination.position - raycastOrigin.position;

        var tracer = Instantiate(tracerEffect, ray.origin, Quaternion.identity);

        tracer.AddPosition(ray.origin);

        if (Physics.Raycast(ray, out hitInfo))
        {
            //Debug.DrawLine(ray.origin, hitInfo.point, Color.red, 1.0f);

            hitEffect.transform.position = hitInfo.point;
            hitEffect.transform.forward  = hitInfo.normal;
            hitEffect.Emit(1);

            tracer.transform.position = hitInfo.point;
        }

        recoil.GenerateRecoil();
    }
Ejemplo n.º 2
0
    public void Shoot()
    {
        if (equipment.magazineAmmo[(int)weaponSlot] > 0)
        {
            isShooting = true;
            muzzleFlash.Emit(flashSize);
            AudioSource.PlayClipAtPoint(weaponShotSFX, transform.position);
            equipment.RemoveAmmoFromMagazine((int)weaponSlot, 1);

            ray.origin = raycastOrigin.position;
            if (weaponName == "shotgun")
            {
                for (int i = 0; i < 10; i++)
                {
                    float distance = Vector3.Distance(raycastOrigin.position, raycastDestination.position);
                    ray.direction = raycastDestination.position - raycastOrigin.position + new Vector3(Random.Range(-0.03f, 0.03f) * distance, Random.Range(-0.03f, 0.03f) * distance, Random.Range(-0.03f, 0.03f) * distance);
                    if (Physics.Raycast(ray, out hitInfo))
                    {
                        if (hitInfo.point != new Vector3(0.0f, 0.0f, 0.0f))
                        {
                            rockDebris.transform.position = hitInfo.point;
                            rockDebris.transform.forward  = hitInfo.normal;
                            rockDebris.Emit(1);
                        }

                        Debug.DrawLine(ray.origin, hitInfo.point, Color.red, 1.0f);
                    }
                }
            }
            else
            {
                ray.direction = raycastDestination.position - raycastOrigin.position;
                if (Physics.Raycast(ray, out hitInfo))
                {
                    if (hitInfo.point != new Vector3(0.0f, 0.0f, 0.0f))
                    {
                        rockDebris.transform.position = hitInfo.point;
                        rockDebris.transform.forward  = hitInfo.normal;
                        rockDebris.Emit(1);
                    }

                    Debug.DrawLine(ray.origin, hitInfo.point, Color.red, 1.0f);
                }
            }

            recoil.GenerateRecoil(weaponName);
        }
    }
Ejemplo n.º 3
0
    private void Fire(Vector3 target)
    {
        _muzzleFlash.Emit(1);

        Vector3 velocity = (target - _raycastOrigin.position).normalized * _config.BulletSpeed;
        var     bullet   = CreateBullet(_raycastOrigin.position, velocity);

        _bullets.Add(bullet);

        _weaponRecoil.GenerateRecoil();

        //if (_config.IsAutomatic) _audioSoruce.PlayOneShot(_config.ContinuousFire);
        //else _audioSoruce.PlayOneShot(_config.StartFire);

        _audioSoruce.PlayOneShot(_config.ContinuousFire);
    }
    private void FireBullet()
    {
        if (ammoCount <= 0)
        {
            return;
        }
        ammoCount--;

        foreach (var particle in muzzleFlash)
        {
            particle.Emit(1);
        }
        Vector3 velocity = (raycastDestination.position - raycastOrigin.position).normalized * bulletSpeed;
        var     bullet   = CreateBullet(raycastOrigin.position, velocity);

        bullets.Add(bullet);

        recoil.GenerateRecoil(weaponName);
    }
Ejemplo n.º 5
0
    private void RaycastShot()
    {
        RaycastHit hit;

        Ray     r           = GetRay();
        Vector3 hitPosition = r.origin + r.direction * 200.0f;

        if (Physics.Raycast(r, out hit, 1000.0f, ~(1 << 9), QueryTriggerInteraction.Ignore))
        {
            Renderer renderer = hit.collider.GetComponentInChildren <Renderer>();
            ImpactManager.Instance.PlayImpact(hit.point, hit.normal, renderer == null ? null : renderer.sharedMaterial);

            //if too close, the trail effect would look weird if it arced to hit the wall, so only correct it if far
            if (hit.distance > 5.0f)
            {
                hitPosition = hit.point;
            }

            Health target = hit.collider.gameObject.GetComponent <Health>();
            if (target != null)
            {
                target.GotDamage(weaponManager.gameObject, weaponStats.damage);
            }
        }

        if (prefabRayTrail != null)
        {
            if (weaponManager.OwnerIsPlayer)
            {
                CreateRayTrail(GetCorrectedMuzzlePlace(), hitPosition);
            }
            else
            {
                CreateRayTrail(endPoint.position, hitPosition);
            }
        }

        if (m_WeaponRecoil != null)
        {
            m_WeaponRecoil.GenerateRecoil();
        }
    }