Exemple #1
0
    void ProcessWeaponHit(GameObject a_hitObject)
    {
        Player hitPlayer = null;

        //try to find a player component
        if (!a_hitObject.TryGetComponent <Player>(out hitPlayer))
        {
            hitPlayer = a_hitObject.GetComponentInParent <Player>(); //try to get the component from parent
        }

        //if the object hit has a player component, deal damage
        if (hitPlayer)
        {
            float damageToInflict = damagePerBullet;
            //check for headshot
            if (a_hitObject.TryGetComponent <Head>(out var playerHead))
            {
                damageToInflict *= headshotMultiplier;

                GameUI.instance.ActivateHitmarker(GameUI.HitmarkerType.headshot);
                audioSource.PlayOneShot(headshotSound, 0.25f);
            }
            else
            {
                GameUI.instance.ActivateHitmarker(GameUI.HitmarkerType.regular);
                audioSource.PlayOneShot(bodyHitSound, 1f);
            }

            //send player hit event
            var playerHitEvt = PlayerHitEvent.Create(Bolt.GlobalTargets.Everyone, Bolt.ReliabilityModes.ReliableOrdered);

            playerHitEvt.PlayerHitNum    = hitPlayer.playerNum;
            playerHitEvt.DamageToInflict = damageToInflict;
            playerHitEvt.Send();

            return;
        }

        //try to find a health component
        if (a_hitObject.TryGetComponent <Health>(out var objectHitHealth))
        {
            float damageToInflict = damagePerBullet;

            //check for headshot
            if (a_hitObject.TryGetComponent <Head>(out var head))
            {
                damageToInflict *= headshotMultiplier;
            }

            objectHitHealth.TakeDamage(damageToInflict);

            return;
        }
    }
Exemple #2
0
 void PlayerHitCheck()
 {
     Physics.Raycast(Spawnpoints.bulletSpawnPoint.position, Spawnpoints.bulletSpawnPoint.forward, out RaycastHit hit);
     if (hit.collider != null && hit.collider.CompareTag("FPSPlayer"))
     {
         var evnt = PlayerHitEvent.Create();
         evnt.attacker       = attacker.text;
         evnt.targetEntity   = hit.collider.gameObject.GetComponent <BoltEntity>();
         evnt.damage         = Random.Range(30, 35);
         evnt.attackerEntity = myEntity;
         evnt.Send();
     }
 }