Example #1
0
        // Set weapon locally
        public void SetWeaponLocally(string weaponID)
        {
            if (_weapon != null && weaponID == _weapon.weaponID)
                return;

            foreach (GameObject wpn in weapons) {
                if (wpn.GetComponent<Weapon> ().weaponID == weaponID){

                    //destroy current weapon
                    foreach (Transform child in transform) {
                        if (child.gameObject.tag == "Weapon") {
                            Destroy (child.gameObject);
                        }
                    }
                    // create the named weapon
                    GameObject weapon = Instantiate (wpn);
                    weapon.transform.SetParent (this.transform, false);
                    _weapon = weapon.GetComponent<Weapon> ();
                    if (!_isLocalPlayer)
                        return;
                    UpdateConfiguration ();

                    weaponsHud.SelectWeapon(_weapon.slot);
                }
            }
        }
Example #2
0
        public void Init(string[] primaryWeapons = null)
        {
            weaponList = FindObjectOfType<WeaponConfigModel>().GetData(); // WeaponModel.Instance.GetData ();

            _gameController = transform.root.gameObject;
            PlayerObjectReferences playerObjects = _gameController.GetComponent<PlayerObjectReferences>();

            character = playerObjects.character;
            characterWeight = character.weight;
            //get default weapon
            foreach (Transform child in transform) {
                if (child.gameObject.tag == "Weapon") {
                    GameObject weapon = child.gameObject;
                    _weapon = weapon.GetComponent<Weapon> ();
                    UpdateConfiguration ();
                }
            }

            _isOffline = GameObject.FindObjectOfType<PlayersManager> ().isOffline;
            if (_isOffline) {
                // offline
                _isLocalPlayer = true;

                //_combatOffline = _gameController.GetComponent<CombatOffline> ();
                _OfflinePlayerController = _gameController.GetComponent<OfflinePlayerController> ();
                ID = _OfflinePlayerController.ID;
            } else {
                // online
                _MultiplayerPlayerController = _gameController.GetComponent<MultiplayerPlayerController> ();
                _isLocalPlayer = _MultiplayerPlayerController.isLocalPlayer;
                ID = _MultiplayerPlayerController.ID;
                _combat = _gameController.GetComponent<Combat> ();
                _combat.OnGotSpecialWeapon += GotSpecialWeapon;
                _CombatAmmoSync = _gameController.GetComponent<CombatAmmoSync> ();
                _combat.OnRevive += SetInitialWeapons;
            }

            if (_isLocalPlayer) {
                weaponsHud = FindObjectOfType<WeaponsHud> ();

                if (primaryWeapons != null) {
                    equippedPrimaryWeapons = primaryWeapons;
                    SetInitialWeapons();
                }

                hud = FindObjectOfType<HudController> ();
                hud.OnWeaponChanged += SetWeapon;

                weaponsHud.SetWeapon (currentPrimary, WeaponSlots.Primary);
                //weaponsHud.SetWeapon (currentSpecial, WeaponSlots.Special);
                weaponsHud.SetWeapon (currentTossable, WeaponSlots.Tossable);

                weaponsHud.UpdateWeaponInfo (1 , _combat.grenadesAmmo , _combat.maxGrenadesAmmo , WeaponSlots.Tossable);
                weaponsHud.SelectWeapon(WeaponSlots.Primary);

                _combat.OnHoldingDelivery += HoldingDelivery;
            }
        }