I'm new and need help with RPC

I've googled it but still stuck in this:

I'm trying to make that when a projectile hits the enemy it sends a message to him to recieve damage but doesn't work.

I instantiate the projectile with PhotonNetwork.Instantiate and when collide:
Script in the projectile:
void OnCollisionEnter(Collision other)
{
if (other.gameObject.name == "Player(Clone)")
{
if (photonView.isMine)
{
photonView.RPC("ApplyDamage", PhotonTargets.All, 10.0f);
}
}PhotonNetwork.Destroy(Adestruir);
}
The receiving damage script in the enemy:

public void ApplyDamage(float dmg)
{
playerHealth -= dmg;
}

Anyone can help me? I dont understand so much RPCs

Comments

  • Jaudatus
    Jaudatus
    edited December 2018
    Hi,

    don't forget the [PunRPC] attribute:
    [PunRPC] // Attribute
    public void ApplyDamage(float dmg)
    {
    playerHealth -= dmg;
    Debug.Log("Damage should get applied now");
    }

    Also check if the ApplyDamage method gets called anyway (added a debug log to check).

    Greets