Ok, i’ve made a simple test with a cube to appear and it works great, so there’s a problem in my script.
If someone find something weard, there it is :
public int currentWeapon = 0;
public int maxWeapons = 2;
public Transform WeapA;
public Transform WeapB;
public Transform WeapC;
public NetworkView nView;
// Use this for initialization
void Start () {
SelectWeapon (0);
nView = GetComponent ();
}
// Update is called once per frame
void Update ()
{
if (Input.GetAxis (“Mouse ScrollWheel”) < 0)
{
if (currentWeapon + 1 <= maxWeapons)
{
currentWeapon ++;
}
else
{
currentWeapon = 0;
}
SelectWeapon (currentWeapon);
}
else if (Input.GetAxis (“Mouse ScrollWheel”) > 0)
{
if (currentWeapon - 1 >= 0)
{
currentWeapon–;
} else {
currentWeapon = maxWeapons;
}
SelectWeapon (currentWeapon);
}
if (currentWeapon == maxWeapons + 1)
{
currentWeapon = 0;
}
if (currentWeapon == -1)
{
currentWeapon = maxWeapons;
}
if (Input.GetKeyDown (KeyCode.Alpha1))
{
currentWeapon = 0;
SelectWeapon (currentWeapon);
}
if (Input.GetKeyDown (KeyCode.Alpha2))
{
currentWeapon = 1;
SelectWeapon (currentWeapon);
}
if (Input.GetKeyDown (KeyCode.Alpha3))
{
currentWeapon = 2;
SelectWeapon (currentWeapon);
}
}
void SelectWeapon (int index)
{
if (GetComponent().isMine){
for (int i = 0; i < transform.childCount; i ++)
{
//Activate the selected weapon
if ( i == index)
{
if ( transform.GetChild (i).name == "WeapA)
{
nView.RPC(“GetWeapA”, RPCMode.All);
}
if ( transform.GetChild (i).name == “WeapB”)
{
nView.RPC(“GetWeapB”, RPCMode.All);
}
if ( transform.GetChild (i).name == “BallOfPee”)
{
nView.RPC(“GetWeapC”, RPCMode.All);
}
}
}
}
}
[RPC]
void GetWeapA ()
{
WeapA.gameObject.SetActive (true);
WeapB.gameObject.SetActive (false);
WeapC.gameObject.SetActive (false);
}
[RPC]
void GetWeapB ()
{
WeapA.gameObject.SetActive (false);
WeapB.gameObject.SetActive (true);
WeapC.gameObject.SetActive (false);
}
[RPC]
void GetWeapC ()
{
WeapA.gameObject.SetActive (false);
WeapB.gameObject.SetActive (false);
WeapC.gameObject.SetActive (true);
}
}