// called from the rigidbody that collides. public void MissileCollided(Transform impactPoint) { // load the correct audio mixer // AudioMixer mixer = dataComps.audioHandler_ref.mixer; // aSource.outputAudioMixerGroup = mixer.FindMatchingGroups("Enemies")[0]; // activate effects, disable core, play imp[act sound elementalMissileEffects [elementIndex].missileCore.enabled = false; elementalMissileEffects [elementIndex].missileImpact.SetActive(true); elementalMissileEffects [elementIndex].missileImpact.transform.position = impactPoint.position; // AudioSource.PlayClipAtPoint(elementalMissileEffects[elementIndex].impactSound, impactPoint.position, 1.0f); AudioSource gs = PlayAudioAtPos.PlayClipAt(elementalMissileEffects[elementIndex].impactSound, impactPoint.position, 1.0f); gs.spatialBlend = (0.8f); // gs.outputAudioMixerGroup = mixer.FindMatchingGroups("Enemies")[0]; // calculate distance with player to inflict damage distanceChecker = Vector3.Distance(impactPoint.position, player_Pos.position); // if impact missile is whithin impact range. if (distanceChecker <= impactRange) { // damage player player_ref.ApplyDamage(elementalMissileEffects[elementIndex].damage); } Destroy(gameObject, 3.0f); }
void PickUpItem(GameObject user) { FPSPlayerComponent = user.GetComponent <FPSPlayer>(); if (FPSPlayerComponent.hitPoints < FPSPlayerComponent.maximumHitPoints) { //heal player FPSPlayerComponent.HealPlayer(healthToAdd); if (pickupSound) { PlayAudioAtPos.PlayClipAt(pickupSound, myTransform.position, 0.75f); } if (removeOnUse) { FreePooledObjects(); //remove this pickup Object.Destroy(gameObject); } } else { //player is already at max health, just play beep sound effect if (fullSound) { PlayAudioAtPos.PlayClipAt(fullSound, myTransform.position, 0.75f); } } }
void OnTriggerEnter(Collider col) { if (fenceRustles.Length > 0 && (col.gameObject.layer == 11 || col.gameObject.layer == 13)) { PlayAudioAtPos.PlayClipAt(fenceRustles[Random.Range(0, fenceRustles.Length)], transform.position, rustleVol); } }
void OnTriggerEnter(Collider other) { if (other.CompareTag("BlockMagnet")) // checks for the player Block magnet in order to be picked up. { FPSPlayerComponent = other.transform.parent.GetComponent <FPSPlayer> (); if (FPSPlayerComponent.hitPoints < FPSPlayerComponent.maximumHitPoints) { //heal player FPSPlayerComponent.HealPlayer(healthToAdd); if (pickupSound) { PlayAudioAtPos.PlayClipAt(pickupSound, myTransform.position, 0.75f); } if (removeOnUse) { FreePooledObjects(); //remove this pickup Object.Destroy(gameObject); } } else { //player is already at max health, just play beep sound effect if (fullSound) { PlayAudioAtPos.PlayClipAt(fullSound, myTransform.position, 0.75f); } } } }
//damage NPC public void ApplyDamage(float damage, Vector3 attackDir, Vector3 attackerPos, Transform attacker, bool isPlayer, bool isExplosion) { if (AIComponent && AIComponent.CharacterDamageComponent) { if (isPlayer) //if attack is from player, pass damage info to main CharacterDamage.cs component { AIComponent.CharacterDamageComponent.ApplyDamage(damage * damageMultiplier, attackDir, attackerPos, attacker, isPlayer, isExplosion, thisRigidBody, damageForce); if (headShot && !headShotState && AIComponent.CharacterDamageComponent.hitPoints <= 0.0f && Vector3.Distance(myTransform.position, attackerPos) < 15f && !isExplosion) { PlayAudioAtPos.PlayClipAt(headShot, myTransform.position, 0.6f, 0f); if (sloMoKillChance >= Random.value && isPlayer) { AIComponent.PlayerWeaponsComponent.FPSPlayerComponent.StartCoroutine(AIComponent.PlayerWeaponsComponent.FPSPlayerComponent.ActivateBulletTime(sloMoTime)); } headShotState = true; //only play head shot sound for one shot, so shotguns won't play many sound effects at once for each hit } } else //attack is not from player, pass damage info to main CharacterDamage.cs component { AIComponent.CharacterDamageComponent.ApplyDamage(damage, attackDir, attackerPos, attacker, isPlayer, isExplosion, thisRigidBody, damageForce); } } else { //body part collider hit without reference to its main AI.cs component Debug.Log("<color=red>LocationDamage.cs:</color> NPC body part hit without reference to its main AI.cs script component, please set reference in inspector."); } }
void OnTriggerEnter(Collider col) { string colTag = col.gameObject.tag; Transform colTransform = col.gameObject.transform; //play splash effects for player and objects thrown into water if ((colTag == "Player" && (FPSWalkerComponent.jumping || !FPSWalkerComponent.grounded)) || //play splash effects for player if they jumped into water ((colTag == "Usable" || //play splash effects for objects if they hit water colTag == "Metal" || colTag == "Wood" || colTag == "Glass" || colTag == "Flesh" || col.gameObject.name == "Chest") && colTransform.position.y > myTransform.GetComponent <Collider>().bounds.max.y - 0.4f) && lastSplashTime + 0.6f < Time.time) { if (colTag == "Player") { EnterWater(col); if (FootstepsComponent.waterLand) { PlayAudioAtPos.PlayClipAt(FootstepsComponent.waterLand, col.gameObject.transform.position, 1.0f, 0.0f); //play splash sound } } else { if (FootstepsComponent.waterLand) { PlayAudioAtPos.PlayClipAt(FootstepsComponent.waterLand, colTransform.position, 1.0f); //play splash sound } } if (waterSplash) { foreach (Transform child in waterSplash.transform) //emit all particles in the particle effect game object group stored in impactObj var { if (child.name == "FastSplash") { splashPos = new Vector3(colTransform.position.x, myTransform.GetComponent <Collider>().bounds.max.y - 0.15f, colTransform.position.z); child.GetComponent <ParticleEmitter>().transform.position = splashPos; } else { splashPos = new Vector3(colTransform.position.x, myTransform.GetComponent <Collider>().bounds.max.y + 0.01f, colTransform.position.z); child.GetComponent <ParticleEmitter>().transform.position = splashPos; } child.GetComponent <ParticleEmitter>().transform.rotation = Quaternion.FromToRotation(Vector3.up, waterSplash.transform.up); //rotate impact effects so they are perpendicular to surface hit child.GetComponent <ParticleEmitter>().Emit(); //emit the particle(s) } } lastSplashTime = Time.time; } }
void OnCollisionEnter(Collision collision) { //play a bounce sound when shell object collides with a surface if (soundState) { if (shellSounds.Length > 0) { PlayAudioAtPos.PlayClipAt(shellSounds[(int)Random.Range(0, (shellSounds.Length))], myTransform.position, 0.75f); } soundState = false; } }
public void PickUpItem() { //if player has less than max ammo for this weapon, give player ammoToAdd amount if (WeaponBehaviorComponent.ammo < WeaponBehaviorComponent.maxAmmo) { if (WeaponBehaviorComponent.ammo + ammoToAdd > WeaponBehaviorComponent.maxAmmo) { //just give player max ammo if they only are a few bullets away from having max ammo WeaponBehaviorComponent.ammo = WeaponBehaviorComponent.maxAmmo; } else { //give player the ammoToAdd amount WeaponBehaviorComponent.ammo += ammoToAdd; } //play pickup sound if (pickupSound) { PlayAudioAtPos.PlayClipAt(pickupSound, myTransform.position, 0.75f); } //equip/activate weapon if we picked up ammo for disposable, one-shot weapon like grenades if (!WeaponBehaviorComponent.doReload && !WeaponBehaviorComponent.haveWeapon && !WeaponBehaviorComponent.nonReloadWeapon) { WeaponBehaviorComponent.haveWeapon = true; PlayerWeaponsComponent.StartCoroutine(PlayerWeaponsComponent.SelectWeapon(WeaponBehaviorComponent.weaponNumber)); } if (removeOnUse) { FreePooledObjects(); if (objectPoolIndex == 0) { //remove this weapon pickup Object.Destroy(gameObject); } else { AzuObjectPool.instance.RecyclePooledObj(objectPoolIndex, myTransform.gameObject); } } } else { //if player is at max ammo, just play beep sound if (fullSound) { PlayAudioAtPos.PlayClipAt(fullSound, myTransform.position, 0.75f); } } }
void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "Player") { FPSPlayer player = col.GetComponent <FPSPlayer>(); if (player && !fxPlayed) { player.ApplyDamage(player.maximumHitPoints + 1.0f); PlayAudioAtPos.PlayClipAt(squishSnd, player.transform.position, 0.75f); crushTime = Time.time; fxPlayed = true; } } }
void RemovePickup() { //play pickup sound if (pickupSound) { PlayAudioAtPos.PlayClipAt(pickupSound, myTransform.position, 0.75f); } if (removeOnUse) { FreePooledObjects(); //remove this weapon pickup from the scene Object.Destroy(gameObject); } }
public void PickUpItem() { LevelManager.instance.keyPicked(); Debug.Log("KeyPicked"); //if player is thirsty, apply thirstToRemove to thirstPoints if (FPSPlayerComponent.thirstPoints > 0.0f && FPSPlayerComponent.usePlayerThirst) { if (FPSPlayerComponent.thirstPoints - thirstToRemove > 0.0) { FPSPlayerComponent.UpdateThirst(-thirstToRemove); } else { FPSPlayerComponent.UpdateThirst(-FPSPlayerComponent.thirstPoints); } //restore player health by healthToRestore amount if (FPSPlayerComponent.hitPoints + healthToRestore < FPSPlayerComponent.maximumHitPoints) { FPSPlayerComponent.HealPlayer(healthToRestore); } else { FPSPlayerComponent.HealPlayer(FPSPlayerComponent.maximumHitPoints - FPSPlayerComponent.hitPoints); } //play pickup sound if (pickupSound) { PlayAudioAtPos.PlayClipAt(pickupSound, myTransform.position, 0.75f); } if (removeOnUse) { FreePooledObjects(); //remove this drink pickup Object.Destroy(gameObject); } } else { //if player not thirsty, just play beep sound if (fullSound) { PlayAudioAtPos.PlayClipAt(fullSound, myTransform.position, 0.75f); } } }
public void PickUpItem() { //if player is hungry, apply hungerToRemove to hungerPoints if (FPSPlayerComponent.hungerPoints > 0.0f && FPSPlayerComponent.usePlayerHunger) { if (FPSPlayerComponent.hungerPoints - hungerToRemove > 0.0) { FPSPlayerComponent.UpdateHunger(-hungerToRemove); } else { FPSPlayerComponent.UpdateHunger(-FPSPlayerComponent.hungerPoints); } //restore player health by healthToRestore amount if (FPSPlayerComponent.hitPoints + healthToRestore < FPSPlayerComponent.maximumHitPoints) { FPSPlayerComponent.HealPlayer(healthToRestore); } else { FPSPlayerComponent.HealPlayer(FPSPlayerComponent.maximumHitPoints - FPSPlayerComponent.hitPoints); } //play pickup sound if (pickupSound) { PlayAudioAtPos.PlayClipAt(pickupSound, myTransform.position, 0.75f); } if (removeOnUse) { FreePooledObjects(); //remove this food pickup Object.Destroy(gameObject); } } else { //if player is not hungry, just play beep sound if (fullSound) { PlayAudioAtPos.PlayClipAt(fullSound, myTransform.position, 0.75f); } } }
//this method called if NPC has died and has more than one capsule collider for collision, so transition to ragdoll void RagDollDie(Rigidbody hitBody, float bodyForce) { if (dieSound) { randomNumber = Random.Range(0, painSounds.Length); PlayAudioAtPos.PlayClipAt(painSounds [randomNumber], transform.position, 1.0f); } AIComponent.NPCRegistryComponent.UnregisterNPC(AIComponent); //unregister NPC from main NPC registry if (AIComponent.spawned && AIComponent.NPCSpawnerComponent) { AIComponent.NPCSpawnerComponent.UnregisterSpawnedNPC(AIComponent); //unregister NPC from spawner registry } if (!AIComponent.useMecanim) { AIComponent.AnimationComponent.enabled = false; } else { AIComponent.AnimatorComponent.enabled = false; } ragdollActive = true; if (AIComponent.NPCAttackComponent.muzzleFlash) { AIComponent.NPCAttackComponent.muzzleFlash.enabled = false; } AIComponent.NPCAttackComponent.enabled = false; AIComponent.StopAllCoroutines(); AIComponent.agent.enabled = false; AIComponent.enabled = false; StartCoroutine(ApplyForce(hitBody, bodyForce)); //initialize the RemoveBody.cs script attached to the NPC ragdoll if (RemoveBodyComponent) { if (removeBody) { RemoveBodyComponent.enabled = true; RemoveBodyComponent.bodyStayTime = bodyStayTime; //pass bodyStayTime to RemoveBody.cs script } else { RemoveBodyComponent.enabled = false; } } }
//this method called if the NPC dies and only has one capsule collider for collision //which will be instantiated in place of the main NPC object (which is removed from the scene) void Die() { RaycastHit rayHit; // Play a dying audio clip if (dieSound) { PlayAudioAtPos.PlayClipAt(dieSound, transform.position, 1.0f); } AIComponent.NPCRegistryComponent.UnregisterNPC(AIComponent); //unregister NPC from main NPC registry if (AIComponent.spawned && AIComponent.NPCSpawnerComponent) { AIComponent.NPCSpawnerComponent.UnregisterSpawnedNPC(AIComponent); //unregister NPC from spawner registry } AIComponent.agent.Stop(); AIComponent.StopAllCoroutines(); // Replace NPC object with the dead body if (deadReplacement) { //drop arrows if corpse disappears ArrowObject[] arrows = gameObject.GetComponentsInChildren <ArrowObject>(true); foreach (ArrowObject arr in arrows) { arr.transform.parent = null; arr.myRigidbody.isKinematic = false; arr.myBoxCol.isTrigger = false; arr.gameObject.tag = "Usable"; arr.falling = true; } dead = Instantiate(deadReplacement, transform.position, transform.rotation) as Transform; RemoveBodyComponent = dead.GetComponent <RemoveBody>(); // Copy position & rotation from the old hierarchy into the dead replacement CopyTransformsRecurse(transform, dead); Collider[] colliders = dead.GetComponentsInChildren <Collider>(); foreach (Collider col in colliders) { Physics.IgnoreCollision(col, AIComponent.FPSWalker.capsule, true); } //apply damage force to NPC ragdoll if (Physics.SphereCast(attackerPos2, 0.2f, attackDir2, out rayHit, 750.0f, raymask) && rayHit.rigidbody && attackDir2.x != 0) { //apply damage force to the ragdoll rigidbody hit by the sphere cast (can be any body part) rayHit.rigidbody.AddForce(attackDir2 * 10.0f, ForceMode.Impulse); } else //apply damage force to NPC ragdoll if being damaged by an explosive object or other damage source without a specified attack direction { Component[] bodies; bodies = dead.GetComponentsInChildren <Rigidbody>(); foreach (Rigidbody body in bodies) { if (explosionCheck) { //if(body.transform.name == "Chest"){//only apply damage force to the chest of the ragdoll if damage is from non-player source //calculate direction to apply damage force to ragdoll body.AddForce((myTransform.position - (attackerPos2 + (Vector3.up * -2.5f))).normalized * Random.Range(4.5f, 7.5f), ForceMode.Impulse); //} } else { if (body.transform.name == "Chest") //only apply damage force to the chest of the ragdoll if damage is from non-player source //calculate direction to apply damage force to ragdoll { body.AddForce((myTransform.position - attackerPos2).normalized * 10.0f, ForceMode.Impulse); } } } } //initialize the RemoveBody.cs script attached to the NPC ragdoll if (RemoveBodyComponent) { if (removeBody) { RemoveBodyComponent.enabled = true; RemoveBodyComponent.bodyStayTime = bodyStayTime; //pass bodyStayTime to RemoveBody.cs script } else { RemoveBodyComponent.enabled = false; } } //Determine if this object or parent should be removed. //This is to allow for different hit detection collider types as children of NPC parent. if (notParent) { Destroy(transform.parent.gameObject); } else { if (AIComponent.factionNum == 3) { killEnemiesRef.EnemyCounter -= 1; } Destroy(transform.gameObject); } } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Draw Impact Effects ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public bool ImpactEffects(Collider hitcol, Vector3 hitPoint, bool NpcAttack, bool meleeAttack, Vector3 rayNormal = default(Vector3)) { WeaponBehaviorComponent = PlayerWeaponsComponent.CurrentWeaponBehaviorComponent; // if(!meleeAttack || NpcAttack){//not a melee weapon //find the tag name of the hit game object and emit the particle effects for the surface type switch (hitcol.gameObject.tag) { case "Dirt": impactObj = dirtImpact; //set impactObj to the particle effect game object group for this surface type if (!meleeAttack) { if (defaultImpactSounds[0]) { hitSound = defaultImpactSounds[Random.Range(0, defaultImpactSounds.Length)]; //select random impact sound for this surface type } } else { if (defaultImpactSoundsMelee[0]) { hitSound = defaultImpactSoundsMelee[Random.Range(0, defaultImpactSoundsMelee.Length)]; //select random impact sound for this surface type } } break; case "Metal": impactObj = metalImpact; if (!meleeAttack) { if (metalImpactSounds[0]) { hitSound = metalImpactSounds[Random.Range(0, metalImpactSounds.Length)]; //select random impact sound for this surface type } } else { if (metalImpactSoundsMelee[0]) { hitSound = metalImpactSoundsMelee[Random.Range(0, metalImpactSoundsMelee.Length)]; //select random impact sound for this surface type } } break; case "Wood": impactObj = woodImpact; if (!meleeAttack) { if (woodImpactSounds[0]) { hitSound = woodImpactSounds[Random.Range(0, woodImpactSounds.Length)]; //select random impact sound for this surface type } } else { if (woodImpactSoundsMelee[0]) { hitSound = woodImpactSoundsMelee[Random.Range(0, woodImpactSoundsMelee.Length)]; //select random impact sound for this surface type } } break; case "Water": impactObj = waterImpact; if (waterImpactSounds[0]) { hitSound = waterImpactSounds[Random.Range(0, waterImpactSounds.Length)]; } break; case "Glass": impactObj = glassImpact; if (waterImpactSounds[0]) { hitSound = glassImpactSounds[Random.Range(0, glassImpactSounds.Length)]; } break; case "Flesh": impactObj = fleshImpact; if (!meleeAttack) { if (fleshImpactSounds[0]) { hitSound = fleshImpactSounds[Random.Range(0, fleshImpactSounds.Length)]; //select random impact sound for this surface type } } else { if (fleshImpactSoundsMelee[0]) { hitSound = fleshImpactSoundsMelee[Random.Range(0, fleshImpactSoundsMelee.Length)]; //select random impact sound for this surface type } } break; case "Stone": impactObj = stoneImpact; if (!meleeAttack) { if (stoneImpactSounds[0]) { hitSound = stoneImpactSounds[Random.Range(0, stoneImpactSounds.Length)]; //select random impact sound for this surface type } } else { if (stoneImpactSoundsMelee[0]) { hitSound = stoneImpactSoundsMelee[Random.Range(0, stoneImpactSoundsMelee.Length)]; //select random impact sound for this surface type } } break; default: impactObj = metalImpact; if (!meleeAttack) { if (defaultImpactSounds[0]) { hitSound = defaultImpactSounds[Random.Range(0, defaultImpactSounds.Length)]; //select random impact sound for this surface type } } else { if (defaultImpactSoundsMelee[0]) { hitSound = defaultImpactSoundsMelee[Random.Range(0, defaultImpactSoundsMelee.Length)]; //select random impact sound for this surface type } } break; } impactObj.transform.position = hitPoint; if (rayNormal != Vector3.zero) { impactObj.transform.rotation = Quaternion.FromToRotation(Vector3.up, rayNormal); } else { impactObj.transform.rotation = Quaternion.Euler(Vector3.up); } if (impactObj.GetComponent <ParticleEmitter>()) { impactObj.GetComponent <ParticleEmitter>().Emit(); } foreach (Transform child in impactObj.transform) //emit all particles in the particle effect game object group stored in impactObj var { child.GetComponent <ParticleEmitter>().Emit(); //emit the particle(s) } //modify the weapon impact sounds based on the weapon type, so the multiple shotgun impacts and automatic weapons aren't so loud if (!NpcAttack && !WeaponBehaviorComponent.meleeActive) { if (WeaponBehaviorComponent.projectileCount > 1) { hitVolumeAmt = 0.2f; } else if (!WeaponBehaviorComponent.semiAuto) { hitVolumeAmt = 0.8f; } else { hitVolumeAmt = 1.0f; } } else { hitVolumeAmt = 1.0f; } //play sounds of bullets hitting surface/ricocheting PlayAudioAtPos.PlayClipAt(hitSound, hitPoint, hitVolumeAmt, 1.0f, 1.0f, 3.0f); return(true); }
void PickUpItem() { //find the PlayerWeapons script in the FPS Prefab to access weaponOrder array PlayerWeapons PlayerWeaponsComponent = Camera.main.transform.GetComponent <CameraControl>().weaponObj.GetComponent <PlayerWeapons>(); WeaponBehavior WeaponBehaviorComponent = weaponObj.GetComponent <WeaponBehavior>(); WeaponBehavior CurrentWeaponBehaviorComponent = PlayerWeaponsComponent.CurrentWeaponBehaviorComponent; //if player does not have this weapon, pick it up if (!WeaponBehaviorComponent.haveWeapon) { //if the player is at max weapons and this weapon takes up an inventory space, drop the current weapon before equipping this one if (PlayerWeaponsComponent.totalWeapons == PlayerWeaponsComponent.maxWeapons && WeaponBehaviorComponent.addsToTotalWeaps) { //determine if this weapon can be dropped (weapons like fists or a sidearm can be set to not be droppable) if (CurrentWeaponBehaviorComponent.droppable) { //drop current weapon if dropCurrentWeapon is true if (removeOnUse && !WeaponBehaviorComponent.dropWillDupe && !CurrentWeaponBehaviorComponent.dropWillDupe) { PlayerWeaponsComponent.DropWeapon(PlayerWeaponsComponent.currentWeapon); } else //replace current weapon if dropCurrentWeapon is false { CurrentWeaponBehaviorComponent.haveWeapon = false; CurrentWeaponBehaviorComponent.dropWillDupe = false; //prevent dropping this weapon and creating duplicated ammo by picking up the weapon again from the non-destroyable pickup item WeaponBehaviorComponent.dropWillDupe = true; } } else //currently held weapon is not dropable, so find next item in the weaponOrder array that is droppable, and drop it { for (int i = PlayerWeaponsComponent.currentWeapon; i < PlayerWeaponsComponent.weaponOrder.Length; i++) { if (PlayerWeaponsComponent.weaponOrder[i].GetComponent <WeaponBehavior>().haveWeapon && PlayerWeaponsComponent.weaponOrder[i].GetComponent <WeaponBehavior>().droppable) { weaponToDrop = i; //found the weapon to drop, break loop break; //no weapon found to drop counting up from current weapon number in weaponOrder array, so start at zero and count upwards } else if (i == PlayerWeaponsComponent.weaponOrder.Length - 1) { for (int n = 0; n < PlayerWeaponsComponent.weaponOrder.Length; n++) { if (PlayerWeaponsComponent.weaponOrder[n].GetComponent <WeaponBehavior>().haveWeapon && PlayerWeaponsComponent.weaponOrder[n].GetComponent <WeaponBehavior>().droppable) { weaponToDrop = n; break; //found the weapon to drop, break loop } } } } if (removeOnUse && !WeaponBehaviorComponent.dropWillDupe) //drop the next weapon if dropCurrentWeapon is true and current weapon is not droppable { PlayerWeaponsComponent.DropWeapon(weaponToDrop); } else //replace the next weapon if dropCurrentWeapon is false and current weapon is not droppable { PlayerWeaponsComponent.weaponOrder[weaponToDrop].GetComponent <WeaponBehavior>().haveWeapon = false; PlayerWeaponsComponent.weaponOrder[weaponToDrop].GetComponent <WeaponBehavior>().dropWillDupe = false; //prevent dropping this weapon and creating duplicated ammo by picking up the weapon again from the non-destroyable pickup item WeaponBehaviorComponent.dropWillDupe = true; } } } //update haveWeapon value of new weapon's WeaponBehavior.cs component WeaponBehaviorComponent.haveWeapon = true; if (!removeOnUse) { WeaponBehaviorComponent.dropWillDupe = true; } else { WeaponBehaviorComponent.dropWillDupe = false; } //select the weapon after picking it up PlayerWeaponsComponent.StartCoroutine(PlayerWeaponsComponent.SelectWeapon(WeaponBehaviorComponent.weaponNumber)); //update the total weapon amount in PlayerWeapons.cs PlayerWeaponsComponent.UpdateTotalWeapons(); //remove pickup item from game world and play sound RemovePickup(); } else //the player already has this weapon, so give them ammo instead { if ((WeaponBehaviorComponent.ammo < WeaponBehaviorComponent.maxAmmo && removeOnUse) && //player is not carrying max ammo for this weapon WeaponBehaviorComponent.meleeSwingDelay == 0) //player is not trying to pick up a melee weapon they already have { if (WeaponBehaviorComponent.ammo + WeaponBehaviorComponent.bulletsPerClip > WeaponBehaviorComponent.maxAmmo) { //just give player max ammo if they only are a few bullets away from having max ammo WeaponBehaviorComponent.ammo = WeaponBehaviorComponent.maxAmmo; } else { //give player the bulletsPerClip amount if they already have this weapon WeaponBehaviorComponent.ammo += WeaponBehaviorComponent.bulletsPerClip; } RemovePickup(); //remove pickup item from game world and play sound } else { //if player has weapon and is at max ammo, just play beep sound if (fullSound) { PlayAudioAtPos.PlayClipAt(fullSound, myTransform.position, 0.75f); } } } }