简体   繁体   中英

Way for faster RPC sending via network with Photon Unity Networking

I am creating 2D top-down shooter using Unity and PUN2. My problem is, RPC calls are taking too much time. My example is whenever player got hit by other players bullet(detected by OnTriggerEnter2D), he sends RPC_message to other players that he got hit, so they could see an effect of hit on him(his decrased HP bar). The time between hit and decrasing HP bar is too long in my opinion, its about 1 second. This causes some trouble while player is getting hit by multiple players with multiple bullets, it is making game less dynamic. Is it any way to speed up an RPC function call? My idea was to synchronize hp values using Object Synchronization, or trying this on collision detection, but im not sure if this gonna be efficient enough.

you haven't to send hit message with RPC.Just sync Health by using OnPhotonSerializeView :

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
    if (stream.IsWriting)
    {
        stream.SendNext(Health);
    }
    else
    {
        Health = (float)stream.ReceiveNext();
    }
}

I made an example about Photon for beginners in my github

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM