예제 #1
0
    protected void HandleHitLogic(RaycastHit hit, int targetMask, int damage, int owner, float range, Vector3 gunLocation, bool enemyShot = false)
    {
        if (((1 << hit.collider.gameObject.layer) & targetMask) != 0) //if the raycast hit an object on the specific layer
        {
            AITakeDamageInterface enemy = null;
            Player p = null;

            if (enemyShot)
            {
                p = hit.collider.transform.root.GetComponent <Player>();
            }
            else
            {
                enemy = hit.collider.transform.root.GetComponent <AITakeDamageInterface>();
            }

            if (enemy != null) //if the raycasted object has a health component
            {
                if (PhotonNetwork.isMasterClient)
                {
                    //Get the distance from the hit and the gun
                    float distance    = Vector3.Distance(hit.point, gunLocation);
                    int   FinalDamage = MathFunc.CalculateDamageDropoff(damage, distance, range);

                    enemy.TakeDamage(owner, FinalDamage, null, AIUtilits.GetCritMultiplier(hit.collider.gameObject));
                }
            }
            else if (p != null)
            {
                if (p.photonView.isMine)
                {
                    p.TakeDamage(damage, Vector3.zero, null);
                }
            }
        }
    }