コード例 #1
0
    void SendBulletFiredEvent(BoltEntity a_playerFiringEntity, Vector3 a_startPos, Vector3 a_endPos, Bolt.PrefabId a_bulletTrailPrefabId)
    {
        var myEvent = PlayerHitscanFiredEvent.Create(a_playerFiringEntity, Bolt.EntityTargets.EveryoneExceptController);

        myEvent.WeaponOwner           = weaponOwner.entity;
        myEvent.BulletStartPos        = a_startPos;
        myEvent.BulletEndPos          = a_endPos;
        myEvent.BulletTrailPrefabId   = a_bulletTrailPrefabId;
        myEvent.FiringSoundName       = firingSound.name;
        myEvent.MuzzleFlashEffectName = muzzleFlashTPP.name;

        myEvent.Send();
    }
コード例 #2
0
    public override void OnEvent(PlayerHitscanFiredEvent evnt)
    {
        if (evnt.FromSelf)
        {
            return;
        }

        if (evnt.WeaponOwner.TryGetComponent <PlayerController>(out var senderController))
        {
            senderController.activeWeapon.animatorTPP.Play("Fire");
        }

        var bulletTrail = BoltNetwork.Instantiate(evnt.BulletTrailPrefabId);

        WeaponHitscan.DrawBulletTrail(evnt.BulletStartPos, evnt.BulletEndPos, bulletTrail.gameObject);

        BoltNetwork.Destroy(bulletTrail);

        GameObject muzzleFlashResource = Resources.Load("Prefabs/VFX/" + evnt.MuzzleFlashEffectName) as GameObject;
        GameObject muzzleFlashGO       = Instantiate(muzzleFlashResource);

        if (muzzleFlashGO.TryGetComponent <ParticleSystem>(out var muzzleFlash))
        {
            muzzleFlashGO.transform.position = evnt.BulletStartPos;
            muzzleFlash.Play();
        }
        Destroy(muzzleFlashGO, 1.2f);

        //firing sound effect
        m_dispondableAudioSource.transform.position = evnt.BulletStartPos;

        AudioClip clip = (AudioClip)Resources.Load("SoundFX/" + evnt.FiringSoundName);

        if (clip)
        {
            m_dispondableAudioSource.PlayOneShot(clip);
        }
    }