Gun Switching not syncing across Network - UNET
Hello, I have a problem where I have my gun switching script working fine. It allows me to click a number and switch to that gun, which is held in an array.
The problem is that when I have two players in my game, the other player cannot see the gun In the other players hand, then can only see their gun.
Here is the GunManager script I have:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class WeaponManager : NetworkBehaviour {
public GameObject[] weapons;
private int nrWeapons;
public int currentWeapon;
void Start() {
SwitchWeapon(0);
nrWeapons = weapons.Length;
}
void Update() {
if (!isLocalPlayer) {
return;
} else {
for (int i = 1; i <= nrWeapons; i++) {
if (Input.GetKeyDown ("" + i)) {
currentWeapon = i - 1;
SwitchWeapon (currentWeapon);
}
}
}
}
void SwitchWeapon(int index) {
for (int i = 0; i < nrWeapons; i++) {
if (i == index) {
weapons [i].gameObject.SetActive (true);
} else {
weapons [i].gameObject.SetActive (false);
}
}
}
}
I have a NetworkIdentity with the LocalPlayerAuthority checked on each. I also have a NetworkTransform on each gun.
Thanks
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612073730im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
uNet Network Sync Problem With Non-Player Object 0 Answers
3D Trajectory Prediction 3 Answers
Moving an object in a curve along the z-axis 0 Answers
Checking if GameObject is withing an other GameObject? 0 Answers