Search Unity

RPC call failed

Discussion in 'Multiplayer' started by AnemoneGX, Nov 26, 2014.

  1. AnemoneGX

    AnemoneGX

    Joined:
    Nov 7, 2014
    Posts:
    1
    I can't seem to fix this error with calling this RPC.
    The error is : RPC call failed because the function 'AddjustCurrentHealth' does not exist in any script attached to'NetworkMaster'

    Attack Script
    Code (CSharp):
    1.  
    2. EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
    3.                 eh.GetComponent<NetworkView>().RPC
    4. ("AddjustCurrentHealth", RPCMode.All, meleebase);
    5.  
    EnemyHealth Script
    Code (CSharp):
    1. [RPC]
    2.     public void AddjustCurrentHealth(int adj){
    3.  
    4.         curHealth -= adj;
    5.  
    6.         if (curHealth < 0)
    7.             curHealth = 0;
    8.         if (curHealth <= 0) {
    9.             Dead ();
    10.                 }
    11.      
    12.         if (curHealth > maxHealth)
    13.             curHealth = maxHealth;
    14.         if (maxHealth < 1)
    15.             maxHealth = 1;
    16.     }
     
  2. OpticalOverride

    OpticalOverride

    Joined:
    Jan 13, 2013
    Posts:
    161
    The networkView.RPC call (that you call in Attack Script) must be called in the same script as the RPC itself (you have it in EnemyHealth Script). Just merge the code you posted into one script, it should work.