Search code examples
c#unity-game-enginegame-developmentmultiplayer

Particle system in netcode for gameobjects


im developing a realistic fps with multiplayer using netcode for gameobjects. Im stuck at trying to get the muzzle flash effect to show for the other player,

im experienced with unity but not with netcode, so sorry if this is a noob question

my particle system is attached to the gun and played with this function:

public void shoot_muzzleflash()
{
    muzzleFlash.Play();
        

}

and im activating this function in an animation with an event. I tried this:

[ServerRpc]
public void CmdStartParticles()
{
    RpcStart_shoot_muzzleflash();
    shoot_muzzleflash();
}

[ClientRpc]
public void RpcStart_shoot_muzzleflash()
{
    shoot_muzzleflash();
}

public void shoot_muzzleflash()
{
    muzzleFlash.Play();
        

}

but then i cant choose the CmdStartParticles() as an event in the animation


Solution

  • figuered it out!

    [ServerRpc]
    public void MuzzleFlashGameobjectServerRpc()
    {
    GameObject go = Instantiate(muzzleflashGobj,
    shootpoint.transform.position,shootpoint.transform.rotation);
    go.GetComponent<NetworkObject>().Spawn();
     
    }
    

    changed the particlesystem to be instantiated at the muzzle point instead of being activated, that worked

    but only when the host shoots do the other clients see, but then the client shoots you cant see it on neither screens. anyone know what this could be?