Esempio n. 1
0
    void OnWeaponHit(Collision collision)
    {
        Player target = UnityHelper.FindObjectUpward <Player>(collision.collider.transform);

        if (target != null)
        {
            if (target.id != this.player.id)
            {
                bool alreadyHit = false;
                foreach (Player p in hitList)
                {
                    if (target == p)
                    {
                        alreadyHit = true;
                        break;
                    }
                }
                if (!alreadyHit)
                {
                    hitList.Add(target);
                    controller.HitOtherPlayer(target, collision.contacts[0].point, 200f);
                }
            }
        }
    }
Esempio n. 2
0
    void Shoot()
    {
        if (player.gun != null)
        {
            player.SetUpperAniState(Player.StateNameHash.shoot);
            Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            Vector3    targetPoint;
            RaycastHit hitInfo;
            if (Physics.Raycast(ray, out hitInfo, 100f, player.hitLayer))
            {
                targetPoint = hitInfo.point;
            }
            else
            {
                targetPoint = Camera.main.transform.position + ray.direction * 100f;
            }

            if (player.gun.Shoot(targetPoint, player.hitLayer, out hitInfo))
            {
                LevelManager lm       = UnityHelper.GetLevelManager();
                Collider     collider = hitInfo.collider;
                if (collider.gameObject.layer == LayerMask.NameToLayer(StringAssets.bodyLayerName))
                {
                    Player p = UnityHelper.FindObjectUpward <Player>(collider.transform);
                    if (p != null)
                    {
                        if (lm != null)
                        {
                            lm.CreateParticleEffect(LevelManager.ParticleEffectType.HitPlayer, hitInfo.point, hitInfo.normal);
                        }
                        controller.HitOtherPlayer(p, hitInfo.point, 100f);
                    }
                    else
                    {
                        Debug.LogError("AimState.Shoot >> hit body, but can't find Player component");
                    }
                }
                else if (collider.gameObject.layer == LayerMask.NameToLayer(StringAssets.groundLayerName))
                {
                    if (lm != null)
                    {
                        lm.CreateParticleEffect(LevelManager.ParticleEffectType.HitGround, hitInfo.point, hitInfo.normal);
                    }
                }
            }

            if (GlobalVariables.hostType == HostType.Server)
            {
                ServerAgent sa = UnityHelper.GetServerAgent();
                sa.SendShoot(player.id, targetPoint);
            }
            else if (GlobalVariables.hostType == HostType.Client)
            {
                ClientAgent ca = UnityHelper.GetClientAgent();
                ca.SendShoot(player.id, targetPoint);
            }
        }
    }