示例#1
0
    protected virtual void Hit(BHealth _other)
    {
        if (stats.m_ExplosionRadius == 0)
        {
            if (_other)
            {
                if (_other.transform != m_Instigator)
                {
                    _other.TakeDamage(stats.m_Damage);
                }
            }
        }

        DestroyProjectile();
    }
示例#2
0
    // Start is called before the first frame update
    public virtual void Init(ProjectileWeapon _stats, Vector3 _velocity, BHealth _target, BHealth _instigator)
    {
        stats = _stats;

        if (_target)
        {
            m_Target = _target.transform;
        }

        m_TargetPosition = transform.position;
        m_TargetRotation = transform.rotation;

        m_ConstantVelocity = _velocity;

        m_Instigator = _instigator.transform;
    }
示例#3
0
    protected virtual void CheckCollision()
    {
        RaycastHit hit;

        if (Physics.Linecast(transform.position, m_TargetPosition, out hit, stats.m_CollisionLayers, QueryTriggerInteraction.Ignore))
        {
            if (hit.transform != m_Instigator)
            {
                transform.up       = hit.normal;
                transform.position = hit.point;

                BHealth other = hit.transform.GetComponent <BHealth>();

                Hit(other);
            }
        }
    }
示例#4
0
    private IEnumerator Shoot()
    {
        BHealth target = null;

        // Burst fire.
        for (int i = 0; i < m_Weapon.m_Bursts; i++)
        {
            if (m_Weapon.m_ShootSound)
            {
                m_Audio.PlayOneShot(m_Weapon.m_ShootSound);
            }

            if (m_Weapon.GetType() == typeof(ProjectileWeapon))
            {
                // Projectile starting position on left / right of camera.
                Vector3    pos = transform.position + transform.forward;
                Quaternion rot = m_TopSegment.rotation;

                if (Vector3.Angle(m_TopSegment.forward, m_Target.transform.position - transform.position) < 20.0f)
                {
                    target = m_Target;
                }

                // Instantiate projectile and initiate stats.
                BProjectile projectile = Instantiate(m_Weapon.m_Model, pos, rot).AddComponent <BProjectile>();

                projectile.Init((ProjectileWeapon)m_Weapon, new Vector3(), target, this);
            }

            // Case for delay between bursts.
            if (m_Weapon.m_BurstDelay != 0.0f)
            {
                yield return(new WaitForSeconds(m_Weapon.m_BurstDelay));
            }
        }
    }
示例#5
0
    private IEnumerator Shoot(int _index, int _weaponID)
    {
        BHealth target = null;
        BWeapon weapon = PlayerParameters.Instance.m_PlayerWeapons[m_CurrWeapons[_index]];

        // Burst fire.
        for (int i = 0; i < weapon.m_Bursts; i++)
        {
            if (m_PlayerAmmo[_weaponID] > 0)
            {
                RecoilWeapons(_index);
                m_PlayerAmmo[_weaponID]--;

                StartCoroutine(m_PMain.m_PCamera.Shake(weapon.m_ShakeMagnitude, weapon.m_ShakeFrequency, weapon.m_ShakeDuration));

                if (weapon.m_ShootSound)
                {
                    m_WeaponAudio[_index].PlayOneShot(weapon.m_ShootSound);
                }

                if (weapon.GetType() == typeof(ProjectileWeapon))
                {
                    // Projectile starting position on left / right of camera.
                    Vector3    pos = transform.position + (transform.rotation * new Vector3(((float)_index - 0.5f) * 8f, -1.5f, 1.0f));
                    Quaternion rot;

                    // Target the surface on the center of the screen.
                    RaycastHit hit;
                    if (Physics.Raycast(pos, SceneCamera.Instance.transform.forward, out hit, Mathf.Infinity, PlayerParameters.Instance.m_TargetingLayers, QueryTriggerInteraction.Ignore))
                    {
                        rot = Quaternion.LookRotation(hit.point - pos);

                        target = hit.transform.GetComponent <BHealth>();
                    }
                    else
                    {
                        rot = SceneCamera.Instance.transform.rotation;
                    }

                    // Instantiate projectile and initiate stats.
                    BProjectile projectile = Instantiate(weapon.m_Model, pos, rot).AddComponent <BProjectile>();

                    projectile.Init((ProjectileWeapon)weapon, m_PMain.m_PMove.m_Velocity, target, m_PMain);
                }
                else
                {
                    GameObject beam = m_BeamEffects[_index];

                    // Projectile starting position on left / right of camera.
                    Vector3    pos = beam.transform.position;
                    Quaternion rot;

                    RaycastHit hit;

                    float distance;

                    if (Physics.Raycast(pos, SceneCamera.Instance.transform.forward, out hit, Mathf.Infinity, PlayerParameters.Instance.m_TargetingLayers, QueryTriggerInteraction.Ignore))
                    {
                        beam.transform.rotation = Quaternion.LookRotation(hit.point - pos);

                        if (Physics.Raycast(pos, hit.point - pos, out hit, Mathf.Infinity, weapon.m_CollisionLayers, QueryTriggerInteraction.Ignore))
                        {
                            BHealth health;

                            if (health = hit.transform.GetComponent <BHealth>())
                            {
                                health.TakeDamage(weapon.m_Damage);
                            }
                        }

                        distance = (hit.point - pos).magnitude;
                    }
                    else
                    {
                        distance = 10000.0f;
                    }

                    Vector3 beamScale = beam.transform.localScale;
                    beamScale.x = ((BeamWeapon)weapon).m_BeamWidth;
                    beamScale.y = ((BeamWeapon)weapon).m_BeamWidth;
                    beamScale.z = distance;

                    beam.transform.localScale = beamScale;

                    beam.SetActive(true);
                }
            }
            else
            {
                m_BeamEffects[_index].SetActive(false);
            }

            // Case for delay between bursts.
            if (weapon.m_BurstDelay != 0.0f)
            {
                yield return(new WaitForSeconds(weapon.m_BurstDelay));
            }
        }
    }