ClientRpc Function not being carried out on clients in Unity3d c#
Hello, Currently I am working on a networked 2d platformer game. I have a script that is supposed to instantiate the players jetpack called JetpackManager. However when the player is spawned into the scene the code only spawns a jetpack into the hosts scene and not into the clients' scenes. This results in only the hosts scene working properly while all the players in the clients' scenes have no jetpacks which avalanches into a ton of problems. This is my code for the JetpackManager (note: I have another script similar to this called weapon manager which is encountering the same problems):
using UnityEngine;
using UnityEngine.Networking;
public class JetpackManager : NetworkBehaviour {
[SerializeField]
private Jetpack[] jetpacks;
[SerializeField]
private Transform jetPackHold;
private PlayerController playerController;
private Jetpack currentJetpack;
void Start(){
playerController = GetComponent<PlayerController> ();
if (isLocalPlayer) {
CmdEquipJetpack (0);
}
}
[Command]
void CmdEquipJetpack(int jetpackNumber){
RpcEquipJetpack (jetpackNumber);
}
[ClientRpc]
void RpcEquipJetpack(int jetpackNumber){
if (currentJetpack != null) {
Destroy (currentJetpack.gameObject);
}
currentJetpack = Instantiate (jetpacks[jetpackNumber], jetPackHold.position, jetPackHold.rotation);
currentJetpack.transform.SetParent (jetPackHold);
playerController.InitialiseJetpackVariables (currentJetpack);
}
}
So essentially my problem is that the code within the RpcEquipJetpack Function is for some reason only being called on the host and not on any of the clients.
Thanks for your help in advance
Your answer
Follow this Question
Related Questions
What's wrong with my script ? 0 Answers
how to connect WEBRTC in unity ? 2 Answers
How do I create a disconnect button in a scene [UNET] 0 Answers
non-player object can't execute's "[Command]"'s attributes 0 Answers
[UNET] Can't spawn players with code 1 Answer