- Home /
Unet RPC call not working on clients
Thanks for checking out my question, I want to activate a third person gun on my player object when the player equips a first person gun. I called an Rpc when the player adds their first person gun to the weapon slot, and then the function searches through the third person gun array looking for the same name, then it enables the correct one. This seems to only work on the host, and not the client. I am not sure what it is I am doing wrong, I read something about not passing arguments to Rpc calls, so I made a global string variable that gets set to the correct gun name before the Rpc is called. Then in the Rpc call it uses that already set global variable, but it still only works for the host. Any help is appreciated, thanks.
PS. I use getcomponent().thirdPersonWeapons because on start up it sets the weapons to a different layer that only other clients can see, so instead of making another array with the exact same gameobjects, I just borrowed the one from the player controller script.
void EnableWeapons () {
if (weaponSlector == 1) {
if (rifle1GO != null) {
rifle1GO.SetActive (true);
weaponName = rifle1GO.name;
RpcEnableThirdPersonWeapon ();
}
if (rifle2GO != null) {
rifle2GO.SetActive (false);
}
}
}
[ClientRpc]
void RpcEnableThirdPersonWeapon () {
for (int i = 0; i < GetComponent<playerController>().thirdPersonWeapons.Length; i++) {
if ( GetComponent<playerController>().thirdPersonWeapons [i].name == weaponName) {
GetComponent<playerController>().thirdPersonWeapons [i].SetActive (true);
} else {
GetComponent<playerController>().thirdPersonWeapons [i].SetActive (false);
}
}
}
Your answer
Follow this Question
Related Questions
Networking pattern for team-based play 1 Answer
RPC isn't called on objects with another name, even though they have the same script. 1 Answer
View ID AllocatedID: # not found during lookup. Strange behaviour may occur 1 Answer
How to use an RPC to send an animation over the network? 2 Answers
Whats wrong with my RPC,!showing clothes on the network 0 Answers