0
\$\begingroup\$

I'm trying to switch between weapons but when I want to display another screen "some example" in client I don't see any change! This screenshot shows what I mean.

[1] : https://i.sstatic.net/fCoBf.jpg "what I mean"

[2] :https://i.sstatic.net/Hj090.jpg "Player Inspector"

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
[RequireComponent(typeof(PlayerShoot))]

public class WeaponManager : NetworkBehaviour
{

     [SerializeField]
     private string weaponLayerName = "Weapon";

     [SerializeField]
     private Transform weaponHolder; // position of weapon :D

     [SerializeField] private PlayerWeapon primaryWeapon;

     [SerializeField] private PlayerWeapon secondaryWeapon;

      [SerializeField] private PlayerWeapon specialWeapon;

      [SerializeField] private PlayerWeapon specialWeaponS;
      [SyncVar] private int currentWeaponIndex = 0;

      private PlayerWeapon currentWeapon;
      private WeaponGraphics currentGraphics;
      private PlayerControllers animm;

      public bool isReloading = false;
      private Animator anim;

      private PlayerShoot playerSh;


   void Start()
    {
        //EquipWeapon(primaryWeapon);

         EquipWeapon(1);
         anim = GetComponent<Animator>();
   }
   public override void OnStartClient()
    {
        //base.OnStartClient();
        EquipWeapon(1);
    }

    public PlayerWeapon GetCurrentWeapon()
     {
        return currentWeapon;
     }

     public WeaponGraphics GetCurrentGraphics()
       {
          return currentGraphics;
       }


     public void EquipWeapon(int _weapon)
      {

         CmdEquipWeapon(_weapon);
         RpcDoEquipWeapon(_weapon);
      }


    [Command]
    public void CmdEquipWeapon(int _weapon)
    {
          RpcDoEquipWeapon(_weapon);
    }


    [ClientRpc]
    public void RpcDoEquipWeapon(int _weapon)
     {

          if (_weapon == currentWeaponIndex)
           return;

          currentWeaponIndex = _weapon;

          switch (_weapon)
           {
             case 0:
                // no weapon
                currentWeapon = null;
                break;
            case 1:
               // primary
                currentWeapon = primaryWeapon;
                break;
            case 2:
                // secondary
                  currentWeapon = secondaryWeapon;
                  break;
            case 3:
                // special
                  currentWeapon = specialWeapon;
                  break;
            case 4:
                 // last one
                  currentWeapon = specialWeaponS;
                  break;
         }

        if (isLocalPlayer)
          {
              currentWeapon.weaponGraphics.SetActive(true);
              Utility.SetLayerRecurcively(currentWeapon.weaponGraphics, LayerMask.NameToLayer(weaponLayerName));
          }
        currentGraphics = currentWeapon.weaponGraphics.GetComponent<WeaponGraphics>();

    }

//[ClientRpc]
//void RpcDoEquipWeapon(int _weapon)
//{
//    if (!isLocalPlayer)
//    {
//        currentWeapon.weaponGraphics.SetActive(true);
//    }
//}



public void Reload()
{

    if (isReloading)
        return;
    anim.SetTrigger("reload");
    StartCoroutine(Relaad_Coroutine());
}

private IEnumerator Relaad_Coroutine()
{
    anim = GetComponent<Animator>();
    anim.SetTrigger("reload");

    Debug.Log("Reloadin . . . ");
    isReloading = true;

    yield return new WaitForSeconds(1f);
    currentWeapon.bullets = currentWeapon.maxBullets; // reload the 0bullets to max bullet = 50
    isReloading = false;
}


[Command]
void CmdOnReload()
{
    RpcOnReload();
}


[ClientRpc]
void RpcOnReload()
{
    anim = GetComponent<Animator>();

    //Animator anim = animm.GetComponent<Animator>();
    if (anim != null)
    {
        anim.SetTrigger("reload");
    }

}
// Update is called once per frame
void Update()
{


    if (!isLocalPlayer)
        return;
    if (Input.GetKeyDown(KeyCode.Alpha1))
    {
        currentWeapon.weaponGraphics.SetActive(false);
        EquipWeapon(3);

    }
    if (Input.GetKeyDown(KeyCode.Alpha2))
    {
        currentWeapon.weaponGraphics.SetActive(false);
        EquipWeapon(2);

    }

    if (Input.GetKeyDown(KeyCode.Alpha3))
    {
        currentWeapon.weaponGraphics.SetActive(false);
        EquipWeapon(1);

    }


 }


 }
\$\endgroup\$
2
  • \$\begingroup\$ My suggestion to you is to take a look at a multiplayer tutorial or read the documentation. I can tell by the way you write your code that you really don't understand the basics of multiplayer development. From this post and your other one on SO. \$\endgroup\$ Commented May 15, 2018 at 13:24
  • \$\begingroup\$ @Dtb49 hmmm, Thank you man, I really did not understand everything in the networks because I was trapped in time and recently started learning networks and on the whole thank you I will try to solve my problem \$\endgroup\$ Commented May 16, 2018 at 0:00

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.