void ChangeWeapon(int weapon) { if (weapon == 1) { StartCoroutine(player.ChangeWeapon(Weapon.Knife)); } else if (weapon == 2) { StartCoroutine(player.ChangeWeapon(Weapon.Pistol)); } else if (weapon == 3) { StartCoroutine(player.ChangeWeapon(Weapon.Rifle)); } else { StartCoroutine(player.ChangeWeapon(Weapon.Shotgun)); } }
public void SwapWeapon(int unitId, Weapon newWeapon) { if (CheckIfCorrectTeam(unitId)) { PlayerBehaviour player = gc.GetPlayerBehaviours()[unitId]; StartCoroutine(player.ChangeWeapon(newWeapon)); } else { throw new System.UnauthorizedAccessException("Error: Can not swap enemy weapon "); } }
private void Awake() { var system = GameObject.FindGameObjectWithTag("System_Online"); movement = system.GetComponent <Movement>(); behaviour = system.GetComponent <PlayerBehaviour>(); playerIndex = GetComponent <IdentifierComponent>().index; render = GetComponent <Renderer>(); render.material.color = Color.red; positionParam.Index = playerIndex; rotationParam.Index = playerIndex; weaponParam.Index = playerIndex; equipmentParam.Index = playerIndex; transform .ObserveEveryValueChanged(x => x.position) .Skip(1) .Subscribe(async position => { positionParam.Position = position; await movement.Move(positionParam); }); transform .ObserveEveryValueChanged(x => x.rotation) .Skip(1) .Subscribe(async rotation => { rotationParam.Rotation = rotation; await movement.Rotation(rotationParam); }); disposable = Observable .EveryUpdate() .Subscribe(async _ => { if (Input.GetKeyDown(KeyCode.Space)) { weaponParam.Main = WeaponType.Pistol; weaponParam.Sub = WeaponType.Rifle; await behaviour.RegisterWeapon(weaponParam); } if (Input.GetKeyDown(KeyCode.C)) { var subCache = weaponParam.Sub; weaponParam.Sub = weaponParam.Main; equipmentParam.MainEquipment = weaponParam.Main = subCache; await behaviour.ChangeWeapon(equipmentParam); } if (Input.GetKeyDown(KeyCode.F)) { var dropItem = new DroppedItem ( Utility.GetRandomValue(), DroppedItemType.Recovery, transform.position ); await behaviour.Drop(dropItem); } if (Input.GetMouseButtonDown(0)) { var transform1 = transform; var shot = new ShotParameter { Index = playerIndex, Position = transform1.position, Rotation = transform1.rotation }; await behaviour.Shot(shot); } if (Input.GetMouseButtonDown(1)) { await behaviour.Reload(playerIndex); } }); }