- Home /
Characters gun dosent activate on network?
hi. i have a networked game that characters should get a gun on start (when they join the game). i have wrote this script and attached it to the characters game object and it seem to work fine but there is one problem : new players that join the game don't see others guns. and i have no idea why is this happening? here is my activation script:
void Start()
{
ActivateSimpleGun();
}
public void ActivateSimpleGun()
{
StartCoroutine(ActiveSGRoutine());
}
IEnumerator ActiveSGRoutine()
{
//this waits for the diactivation to complete
//(in case a new gun was equipped and we want to change it
NetworkWeaponDiactivate();
yield return new WaitUntil(() => AllGunsDiactive == true);
if (isServer) RpcActiveSG();
else CmdActiveSG();
}
[Command]
void CmdActiveSG()
{
SimpleGun.SetActive(true);
WhichGunisOn = 1;
AllGunsDiactive = false;
RpcActiveSG();
}
[ClientRpc]
void RpcActiveSG()
{
SimpleGun.SetActive(true);
WhichGunisOn = 1;
AllGunsDiactive = false;
}
Answer by mbahrami642 · Jul 29, 2018 at 12:32 PM
For anybody who runs into this problem: i found a solution. on every players start i check and find other players in the scene and then check in their weaponpicking script and see what gun is active on them and place the gun for that character (activate it from its childrens ). im sure this is not the best way but it seems to work for now. this the loop to do it:
private GameObject[] AllPlayers;
AllPlayers = GameObject.FindGameObjectsWithTag("Player");
for (int i=0; i < AllPlayers.Length; i++)
{
var CheckingPlayer = AllPlayers[i].GetComponent<WeaponPickingSystem>();
if (!CheckingPlayer.isLocalPlayer)
{
if (CheckingPlayer.WhichGunisOn == GUN_TYPE.simpleGun)
{
CheckingPlayer.SimpleGun.SetActive(true);
}
if (CheckingPlayer.WhichGunisOn == GUN_TYPE.secondGun)
{
CheckingPlayer.SecondGun.SetActive(true);
}
}
}
Your answer
Follow this Question
Related Questions
Trying to send command for object without authority. - change color of object from client 0 Answers
Unity Networking client interaction with scene not displayed on other client. Commands and RPCs 0 Answers
"Trying to send command for object without authority" warning but the object is the localPlayer 1 Answer
Non player objects movements are not syncronized on server 0 Answers
Cmd on a runtime created object 0 Answers