private void EquipWeapon(PlayerWeapon weapon) { _currentWeapon = weapon; GameObject weaponInstance = Instantiate(weapon.Graphics, _weaponHolder.position, _weaponHolder.rotation); weaponInstance.transform.SetParent(_weaponHolder); _currentGraphics = weaponInstance.GetComponent <WeaponGraphics>(); if (_currentGraphics == null) { Debug.LogError("No WeaponGraphics component on the weapon ojbject : " + weaponInstance.name); } if (isLocalPlayer) { Utils.SetLayerRecursive(weaponInstance, LayerMask.NameToLayer(WEAPON_LAYER_NAME)); } }
private void Update() { if (!isLocalPlayer || GameManager.Instance.IsMenuOpen) { return; } _currentWeapon = _weaponManager.GetCurrentWeapon(); var isHit = Physics.Raycast(_camera.transform.position, _camera.transform.forward, out RaycastHit hit, _currentWeapon.Range, _remotePlayerLayer); PlayerSetup.PlayerUI.SetCrossHair(isHit); if (_currentWeapon.FireRate <= 0f) { if (Input.GetButtonDown("Fire1")) { Shoot(); } } else { if (Input.GetButtonDown("Fire1")) { InvokeRepeating(nameof(Shoot), 0f, 1f / _currentWeapon.FireRate); } else if (Input.GetButtonUp("Fire1")) { CancelInvoke("Shoot"); } } }
private void Update() { this._currentWeapon = this._weaponManager.CurrentWeapon; if (this._currentWeapon.fireRate <= 0) { if (Input.GetButtonDown("Fire1")) { this.Shoot(); } } else { if (Input.GetButton("Fire1")) { this.InvokeRepeating("Shoot", 0f, 1f / this._currentWeapon.fireRate); } else if (Input.GetButtonUp("Fire1")) { this.CancelInvoke("Shoot"); } } }