// Add a new weapon to inventory (called by weapon object). public void AddWeapon(InteractiveWeapon newWeapon) { // Position new weapon in player's hand. newWeapon.gameObject.transform.SetParent(rightHand); newWeapon.transform.localPosition = newWeapon.rightHandPosition; newWeapon.transform.localRotation = Quaternion.Euler(newWeapon.relativeRotation); // 무기를 바꿨을때 처리 if (this.weapons[slotMap[newWeapon.type]]) { // Same weapon type, recharge bullets and destroy duplicated object. if (this.weapons[slotMap[newWeapon.type]].label == newWeapon.label) { this.weapons[slotMap[newWeapon.type]].ResetBullets(); ChangeWeapon(activeWeapon, slotMap[newWeapon.type]); GameObject.Destroy(newWeapon.gameObject); return; } // Different weapon type, grab the new one and drop the weapon in inventory. else { this.weapons[slotMap[newWeapon.type]].Drop(); } } // Call change weapon action. this.weapons[slotMap[newWeapon.type]] = newWeapon; ChangeWeapon(activeWeapon, slotMap[newWeapon.type]); }
/// <summary> /// 인벤토리 역활을 하게될 함수 /// </summary> public void AddWeapon(InteractiveWeapon newWeapon) { // newWeapon 위치 조정 newWeapon.gameObject.transform.SetParent(rightHand); newWeapon.transform.localPosition = newWeapon.rightHandPosition; newWeapon.transform.localRotation = Quaternion.Euler(newWeapon.relativeRotation); if (weapons[slotMap[newWeapon.weaponType]]) // 해당 타입의 무기가 이미 있다 { if (weapons[slotMap[newWeapon.weaponType]].label_weaponName == newWeapon.label_weaponName) { // 이름이 같은 무기 -> 이미 해당 슬롯의 같은 무기 착용중인걸 주웠다 // 단순히 총알 리셋, 바꾸는 모션 실행 및 중복 무기 제거 weapons[slotMap[newWeapon.weaponType]].ResetBullet(); ChangeWeapon(activeWeapon, slotMap[newWeapon.weaponType]); Destroy(newWeapon.gameObject); return; } else { // 같은 타입의 다른 무기라면 현재 가지고 있는 무기는 떨굼 weapons[slotMap[newWeapon.weaponType]].Drop(); } } weapons[slotMap[newWeapon.weaponType]] = newWeapon; ChangeWeapon(activeWeapon, slotMap[newWeapon.weaponType]); }
// get the players upgarde after each level change public void PlayerUpgrade() { if (isShooter) // in case of player(Shooter) { try { InteractiveWeapon activeWeapon = this.GetComponent <WeaponHandling>().Weapon; activeWeapon.recoilAngle = 0f; activeWeapon.bulletDamage = 50; activeWeapon.upgradeWeapon(); } catch (Exception e) { print("No Weapon"); } } else if (isDriver) // in case of driver(Shooter) { try { RCC_CarControllerV3 carController = this.GetComponent <RCC_CarControllerV3>(); carController.useNOS = true; carController.useTurbo = true; carController.useExhaustFlame = true; } catch (Exception e) { print("No shooter"); } } }
private void ChangeWeapon(int oldWeapon, int newWeapon) { if (oldWeapon > 0) { InteractiveWeapon oldWP = weapons[oldWeapon]; oldWP.gameObject.SetActive(false); gunMuzzle = null; oldWP.ToggleWeapon(false); } while (weapons[newWeapon] == null && newWeapon > 0) { newWeapon = (newWeapon + 1) % weapons.Count; } InteractiveWeapon newWP = weapons[newWeapon]; if (newWeapon > 0) { newWP.gameObject.SetActive(true); gunMuzzle = newWP.transform.Find("muzzle"); newWP.ToggleWeapon(true); } activeWeapon = newWeapon; if (oldWeapon != newWeapon) { behaviourController.GetAnimator.SetTrigger(changeWeaponTrigger); behaviourController.GetAnimator.SetInteger(weaponType, newWP ? (int)newWP.weaponType : 0); } SetWeaponCrossHair(newWeapon > 0); }
void PickUpWeapon(InteractiveWeapon weapon) { if (weapon.Pickable) { weapon.PickUpWeapon(playerShootBehavior); } ServiceLocator.Current.Get <AudioInput>().PlayAudio(AudioActionType.PickUpWeapon); CollisionInteraction?.Invoke(null); }
private void Update() { float ShootTrigger = Mathf.Abs(Input.GetAxisRaw(ButtonName.Shoot)); if (ShootTrigger > Mathf.Epsilon && isShooting == false && activeWeapon > 0 && burstShotCount == 0) { isShooting = true; ShootWeapon(activeWeapon); } else if (isShooting == true && ShootTrigger < Mathf.Epsilon) { isShooting = false; } else if (Input.GetButtonUp(ButtonName.Reload) && activeWeapon > 0) { InteractiveWeapon weapon = weapons[activeWeapon]; if (weapon.StartReload()) { SoundManager.Instance.PlayOneShotEffect((int)weapon.reloadSound, gunMuzzle.position, 0.5f); behaviourController.GetAnimator.SetBool(reloadBool, true); } } else if (Input.GetButtonDown(ButtonName.Drop) && activeWeapon > 0) { EndReloadWeapon(); int weaponToDrop = activeWeapon; ChangeWeapon(activeWeapon, 0); weapons[weaponToDrop].DropWeapon(); weapons[weaponToDrop] = null; } else { if (Mathf.Abs(Input.GetAxisRaw(ButtonName.Change)) > Mathf.Epsilon && isChangingWeapon == false) { isChangingWeapon = true; int nextWeapon = activeWeapon + 1; ChangeWeapon(activeWeapon, nextWeapon % weapons.Count); } else if (Mathf.Abs(Input.GetAxisRaw(ButtonName.Change)) < Mathf.Epsilon) { isChangingWeapon = false; } } if (isShotAlive == true) { ShotProgress(); } isAiming = behaviourController.GetAnimator.GetBool(aimBool); }
private void OnTriggerExit(Collider other) { if (!isLocalPlayer) { return; } if (other.tag == "Gun") { InteractiveWeapon tempWeapon = other.GetComponent <InteractiveWeapon>(); tempWeapon.pickable = false; tempWeapon.TooglePickupHUD(false, this.playerCamera); } }
public void dropWeapon() { if (!Player || Player.getActiveWeapon() == 0) { return; } Player.EndReloadWeapon(); int weaponToDrop = Player.getActiveWeapon(); Player.ChangeWeapon(Player.getActiveWeapon(), 0); Player.getWeapons()[weaponToDrop].Drop(); Player.getWeapons()[weaponToDrop] = null; this.Weapon = null; }
void pickWeapon(string weaponId) { InteractiveWeapon[] pickedWeapon = GameObject.FindObjectsOfType <InteractiveWeapon>(); foreach (InteractiveWeapon w in pickedWeapon) { if (w.id == weaponId) { w.TooglePickupHUD(false, playerCamera); this.Weapon = w; this.Player.AddWeapon(this.Weapon); return; } } }
// Add a new weapon to inventory (called by weapon object). public void AddWeapon(InteractiveWeapon newWeapon) { // Position new weapon in player's hand. newWeapon.gameObject.transform.SetParent(rightHand); newWeapon.transform.localPosition = newWeapon.rightHandPosition; newWeapon.transform.localRotation = Quaternion.Euler(newWeapon.relativeRotation); // Handle inventory slot conflict. if (this.weapons[slotMap[newWeapon.type]]) { // Same weapon type, recharge bullets and destroy duplicated object. if (this.weapons[slotMap[newWeapon.type]].label == newWeapon.label) { this.weapons[slotMap[newWeapon.type]].ResetBullets(); ChangeWeapon(activeWeapon, slotMap[newWeapon.type]); // GameObject.Destroy(newWeapon.gameObject); return; } // Different weapon type, grab the new one and drop the weapon in inventory. else { this.weapons[slotMap[newWeapon.type]].Drop(); } } // Call change weapon action. this.weapons[slotMap[newWeapon.type]] = newWeapon; ChangeWeapon(activeWeapon, slotMap[newWeapon.type]); newWeapon.GetComponent <SphereCollider>().enabled = false; newWeapon.rbody.isKinematic = true; newWeapon.col.enabled = false; //newWeapon.Toggle(true); newWeapon.pickable = false; // newWeapon.TooglePickupHUD(false); newWeapon.GetComponent <NetworkTransform>().enabled = false; }
/// <summary> /// 인벤토리 역할을 할 함수 /// </summary> public void AddWeapon(InteractiveWeapon newWeapon) { newWeapon.gameObject.transform.SetParent(rightHand); newWeapon.transform.localPosition = newWeapon.rightHandPosition; newWeapon.transform.localRotation = Quaternion.Euler(newWeapon.relativeRotation); if (weapons[slotMap[newWeapon.weaponType]]) { if (weapons[slotMap[newWeapon.weaponType]].label_weaponName == newWeapon.label_weaponName) { weapons[slotMap[newWeapon.weaponType]].ResetBullet(); ChangeWeapon(activeWeapon, slotMap[newWeapon.weaponType]); Destroy(newWeapon.gameObject); return; } else { weapons[slotMap[newWeapon.weaponType]].Drop(); } } weapons[slotMap[newWeapon.weaponType]] = newWeapon; ChangeWeapon(activeWeapon, slotMap[newWeapon.weaponType]); }
//player interaction with weapons void OnTriggerStay(Collider other) { if (!isLocalPlayer) { return; } if (other.tag == "Gun") { InteractiveWeapon tempWeapon = other.GetComponent <InteractiveWeapon>(); tempWeapon.pickable = true; tempWeapon.TooglePickupHUD(true, this.playerCamera); if (Input.GetButtonDown(Player.pickButton) && tempWeapon && tempWeapon.pickable == true)//pick up weapon { this.Weapon = tempWeapon; if (Weapon.label == "AWM") { Player.shotRateFactor = 0.1f; } else { Player.shotRateFactor = 1f; } Player.AddWeapon(Weapon); tempWeapon.TooglePickupHUD(false, this.playerCamera); Weapon.Toggle(true); if (isServer) { RpcpickWeapon(this.Weapon.id); } else { CmdpickWeapon(this.Weapon.id); } } } }