#My rpc call isn't working to get my other players to see i'm punching

1 messages · Page 1 of 1 (latest)

robust jacinth
#
    {
        if(!IsOwner)
        {
            return;
        }

        if(!isPunching)
        {
            punchAnim.Play("Punch");
            isPunching = true;
            PunchRpc();
            hitCollider.enabled = true;
            StartCoroutine(PunchCooldown());
        }
    }

    [Rpc(SendTo.Everyone)]
    public void PunchRpc()
    {
        if (IsOwner) return;
        Debug.Log("punching");
        Punch();
    }```
copper bronze
#

What code runs punchrpc?

#

Does that debug ever run?

#

That animation code will never run cuz you return if they are host and aren’t host

robust jacinth
copper bronze
#

What code runs punchrpc

robust jacinth
#

at the top of the function

copper bronze
#

Whats punchcooldown

robust jacinth
#

oh wait im causing recursion

#

like a lot of it

#

i think thats the word

#

im telling all other clients

#

to run punch on the other client

#

which then causes them to run the rpc

#

and then punch

#

over and over

#

i need to seperate the trigger from the request

#
    public void TriggerPunch()
    {
        if (!IsOwner || !isPunching) return;

        Punch();

        PunchRpc();
    }

    public void Punch()
    {
        punchAnim.Play("Punch");
        isPunching = true;
        hitCollider.enabled = true;
        StartCoroutine(PunchCooldown());
    }

    [Rpc(SendTo.Everyone)]
    public void PunchRpc()
    {
        if (IsOwner) return;
        Punch();
    }

    private IEnumerator PunchCooldown()
    {
        yield return new WaitForSecondsRealtime(0.5f);
        hitCollider.enabled = false;
        isPunching = false;
    }```

for some reason its now casuing all players to punch when one player punches
#

yeah on the client that punched every player punches but on other clients no one is punching