Esempio n. 1
0
    public void Fire(GunFiredDelegate callback)
    {
        long hitId = -1;

        if (GetRaycast(m_Barrel.position, m_Barrel.forward, ref m_HitInfo) == true)
        {
            Debug.Log($"Shot a {m_HitInfo.collider.name}\n", m_HitInfo.collider);
            var cowboy = m_HitInfo.collider.GetComponentInParent <Cowboy>();
            if (cowboy != null)
            {
                var networkClient = cowboy.GetComponentInParent <NetworkClient>();
                if (networkClient != null)
                {
                    if (networkClient.netId.IsEmpty() == false)
                    {
                        hitId = networkClient.netId.Value;
                        CreateEffect(m_HitInfo.point, m_HitInfo.normal, ImpactEffect.Blood);
                    }
                }
            }
            else
            {
                if (m_HitInfo.collider.gameObject.layer == LayerMask.NameToLayer("Breakable"))
                {
                    var breakable = m_HitInfo.collider.GetComponent <BreakableTarget>();

                    if (null != breakable)
                    {
                        breakable.Break(m_HitInfo.point);
                    }
                }

                CreateEffect(m_HitInfo.point, m_HitInfo.normal, ImpactEffect.Wood);
            }
        }

        FireGunShotEffect(m_Barrel.position, m_Barrel.forward);
        callback?.Invoke(m_Barrel.position, m_Barrel.forward, hitId);
    }
Esempio n. 2
0
 public void FireGun(Transform hand, GunFiredDelegate callback)
 {
     m_Gun.Fire(callback);
 }