Advertisement
Guest User

gun

a guest
Jan 10th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 80.36 KB | Source Code | 0 0
  1. using Animancer;
  2. using CodeStage.AntiCheat.ObscuredTypes;
  3. using CodeStage.AntiCheat.Storage;
  4. using DarkTreeFPS;
  5. using SecureVariables;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using TMPro;
  9. using Unity.VisualScripting;
  10. using UnityEngine;
  11. using UnityEngine.UIElements;
  12.  
  13.  
  14. namespace TMG_Gun
  15. {
  16.  
  17.     public class Gun : MonoBehaviour
  18.     {
  19.         public SecureFloat maxDamageToDo = 10f;
  20.         public SecureFloat minDamageToDo = 5f;
  21.         public SecureFloat bulletSpeed = 25f;
  22.         public SecureInt bulletVisual = 0;
  23.         [SerializeField]private SecureBool canADS = true;
  24.         [SerializeField] private SecureBool damageFromCamera = false;
  25.         [SerializeField] private Vector3 adsOffset = Vector3.zero;
  26.         [Header("lower is higher zoom!")]
  27.         [SerializeField] private float adsZoom = 40;
  28.         [SerializeField] private SecureBool useBulletTrail = true;
  29.         [SerializeField] private AnimationClip reloadClip;
  30.         [SerializeField] private AnimancerComponent animancerComponent;
  31.         [SerializeField] private SecureString gunName = "rifle";
  32.         [SerializeField] private SecureBool isAuto = false;
  33.         public GameObject projectile;
  34.         [SerializeField] private SecureBool useProjectile = true;
  35.         [SerializeField] private SecureBool visualFromGun = true;
  36.         [Header("Don't exceed 10k projectile speed unless physics are higher")]
  37.         [Range(200,10000)]public float rangeProjectileSpeed = 100;
  38.         [SerializeField] private SecureBool useReplaceRay = false;
  39.         [SerializeField] private SecureFloat replaceWithRayDistance = 5f;
  40.  
  41.  
  42.         [Header("settings for both modes")]
  43.         [SerializeField] private SecureFloat reloadingTimeMultiplier = 1f; // Strength of the kickback
  44.         [SerializeField] private SecureFloat kickbackStrength = 5f; // Strength of the kickback
  45.         [SerializeField] private SecureFloat fireRate = 0.5f;
  46.         [SerializeField] private SecureFloat sprayAmount = 0.5f; // Control the amount of spray
  47.         [SerializeField] private SecureInt ammoCount = 30; // Control the amount of spray
  48.         [SerializeField] private SecureInt accurateBulletOverrideCount = 2;
  49.         [SerializeField] private SecureFloat accurateBulletResetTime = 1f;
  50.         [SerializeField] private SecureFloat range = 100f;
  51.  
  52.         private SecureBool canFire = true;
  53.         private GameObject ammoPoolObj;
  54.         private ObjectPool objectPool;
  55.         private AudioSource audioSource;
  56.         [Header("Audio")]
  57.         [SerializeField] private SecureFloat volume = 0.1f; // Control the amount of spray
  58.         public AudioClip shootclip;
  59.         private FPS_Controller fpsController;
  60.         private AimDownSights aimDownSights;
  61.         private BulletTrailPooling bulletTrailPool;
  62.         private MuzzleFlashPooling muzzleFlashPooling;
  63.         private SecureInt shotsFired = 0;
  64.         private float accurateTimer = 0;
  65.         private SecureBool isShooting = false;
  66.         public LayerMask mask;
  67.         private MissHitPooling missHitPool;
  68.         private BloodHitPooling bloodHitPool;
  69.         private BloodDecalPooling bloodDecalPool;
  70.         private SecureFloat footPenalty = 2f;
  71.         private SecureFloat handPenalty = 2f;
  72.         private SecureFloat armPenalty = 1.5f;
  73.         private SecureFloat legPenalty = 1.5f;
  74.         private SecureFloat headShotBuff = 2f;
  75.         private bool toggle = false;
  76.         private AimGunAtRaycast aimGunAtRaycast;
  77.         private SecureBool enemyHit;
  78.         private bool bulletShot = false;
  79.         public static bool aimingDownSights;
  80.         public GameObject nextRayCheckObj;
  81.         private GunRoot gunRoot;
  82.         private void OnDrawGizmos()
  83.         {
  84.             // Draw the ray in the editor for debugging purposes
  85.             Gizmos.color = Color.blue;
  86.             Gizmos.DrawLine(transform.position, transform.position + transform.forward * range);
  87.         }
  88.         private void OnEnable()
  89.         {
  90.             aimingDownSights = false;
  91.             toggle = false;
  92.             canFire = true;
  93.             //spawn new pool
  94.             ammoPoolObj = new GameObject();
  95.             objectPool = ammoPoolObj.AddComponent<ObjectPool>();
  96.             objectPool.prefab = projectile;
  97.             objectPool.poolSize = ammoCount;
  98.             objectPool.gameObject.name = "PlayerAmmoPool";
  99.             //objectPool = GameObject.FindGameObjectWithTag("PlayerAmmoPool").GetComponent<ObjectPool>();
  100.  
  101.  
  102.             if(useProjectile)
  103.             {
  104.                 GameManager.usingProjectileGun = true;
  105.             }
  106.             else
  107.             {
  108.                 GameManager.usingProjectileGun = false;
  109.             }
  110.         }
  111.         private void OnDisable()
  112.         {
  113.             //remove pool
  114.             Destroy(ammoPoolObj);
  115.  
  116.         }
  117.         private void Start()
  118.         {
  119.             gunRoot = GetComponentInParent<GunRoot>();
  120.             originalRotation = gunRoot.transform.localRotation;
  121.             otherMask = LayerMask.GetMask("Default");
  122.             ObscuredPrefs.Set<int>(gunName + "_Ammo", ammoCount);
  123.             projectile.GetComponent<Projectile>().maxDamageToDo = maxDamageToDo;
  124.             projectile.GetComponent<Projectile>().minDamageToDo = minDamageToDo;
  125.             fpsController = FindObjectOfType<FPS_Controller>();
  126.             aimDownSights = FindObjectOfType<AimDownSights>();
  127.             bulletTrailPool = FindObjectOfType<BulletTrailPooling>();
  128.             muzzleFlashPooling = FindObjectOfType<MuzzleFlashPooling>();
  129.             audioSource = GetComponentInParent<AudioSource>();
  130.             missHitPool = FindObjectOfType<MissHitPooling>();
  131.             bloodHitPool = FindObjectOfType<BloodHitPooling>();
  132.             bloodDecalPool = FindObjectOfType<BloodDecalPooling>();
  133.             aimGunAtRaycast = GetComponentInParent<AimGunAtRaycast>();
  134.         }
  135.         void Update()
  136.         {
  137.             GameManager.currentAmmo = ObscuredPrefs.Get<int>(gunName + "_Ammo");
  138.             GameManager.currentMaxAmmo = ammoCount;
  139.             //Debug.Log(ObscuredPrefs.Get<int>(gunName + "_Ammo"));
  140.  
  141.             if (GameManager.blockShootingInput == false)
  142.             {
  143.                 if (GameManager.currentAmmo > 0 && GameManager.reloading == false)
  144.                 {
  145.                     if (isAuto)
  146.                     {
  147.                         if (canFire && KeyBindingManager.GetKey(KeyAction.shoot))
  148.                         {
  149.                             StartCoroutine(FireCooldown());
  150.                             RangeAttack();
  151.                         }
  152.                     }
  153.                     else
  154.                     {
  155.                         if (KeyBindingManager.GetKeyDown(KeyAction.shoot))
  156.                         {
  157.                             RangeAttack();
  158.                         }
  159.                     }
  160.                 }
  161.  
  162.                 //check if shooting
  163.                 if (KeyBindingManager.GetKey(KeyAction.shoot))
  164.                 {
  165.                     isShooting = true;
  166.                 }
  167.                 else
  168.                 {
  169.                     isShooting = false;
  170.                 }
  171.             }
  172.  
  173.  
  174.  
  175.             //reload
  176.             if (KeyBindingManager.GetKeyDown(KeyAction.reload) && ObscuredPrefs.Get<int>(gunName + "_Ammo") < ammoCount)
  177.             {
  178.                 StartCoroutine(ReloadGun());
  179.                 GameManager.reloading = true;
  180.             }
  181.  
  182.             //Debug.Log(isShooting);
  183.  
  184.             //accuracy override
  185.             if (shotsFired > 0)
  186.             {
  187.                 //Debug.Log("accuracy timer started");
  188.                 accurateTimer += Time.deltaTime;
  189.                 if (isShooting == false)
  190.                 {
  191.                     if (accurateTimer > accurateBulletResetTime)
  192.                     {
  193.                         //Debug.Log("accuracy timer finished");
  194.                         shotsFired = 0;
  195.                         accurateTimer = 0;
  196.                     }
  197.                 }
  198.                 else
  199.                 {
  200.                     accurateTimer = 0;
  201.                 }
  202.  
  203.             }
  204.  
  205.             if(canADS)
  206.             {
  207.                 if (KeyBindingManager.GetKey(KeyAction.aim) && GameManager.reloading == false)
  208.                 {
  209.                     aimDownSights.mainCamera.fieldOfView = adsZoom;
  210.                     aimDownSights.gunCamera.fieldOfView = adsZoom;
  211.                     aimDownSights.gunRoot.transform.position = aimDownSights.adsPos.transform.position + adsOffset;
  212.                     aimGunAtRaycast.enabled = false;
  213.                     aimDownSights.gunRoot.transform.rotation = Quaternion.LookRotation(aimDownSights.adsPos.transform.forward);
  214.                     aimingDownSights = true;
  215.                     toggle = false;
  216.                 }
  217.                 else
  218.                 {
  219.                     DisableAds();
  220.                 }
  221.             }
  222.             else
  223.             {
  224.                 DisableAds();
  225.             }
  226.         }
  227.         private void DisableAds()
  228.         {
  229.             if (toggle == false)
  230.             {
  231.                 aimDownSights.mainCamera.fieldOfView = 60;
  232.                 aimDownSights.gunCamera.fieldOfView = 60;
  233.                 aimDownSights.gunRoot.transform.position = aimDownSights.gunPos.transform.position;
  234.                 aimGunAtRaycast.enabled = true;
  235.                 aimingDownSights = false;
  236.                 toggle = true;
  237.             }
  238.         }
  239.         IEnumerator ReloadGun()
  240.         {
  241.             shotsFired = 0;
  242.  
  243.             float reloadtime = 1 * reloadingTimeMultiplier;
  244.             float reloadspeed = 1 / reloadingTimeMultiplier;
  245.             var state = animancerComponent.Play(reloadClip);
  246.             state.Speed = reloadspeed;
  247.             // Assuming aimDownSights.gunRoot is your gun's transform
  248.             aimDownSights.gunRoot.transform.position = aimDownSights.reloadPos.transform.position;
  249.  
  250.             // Create a -45-degree rotation Quaternion around the Y axis for local rotation
  251.             Quaternion localRotation45DegreesY = Quaternion.Euler(0, -45, 0);
  252.  
  253.             // Apply the local rotation
  254.             aimDownSights.gunRoot.transform.localRotation = localRotation45DegreesY;
  255.  
  256.             yield return new WaitForSeconds(reloadtime);
  257.  
  258.             animancerComponent.Stop(reloadClip);
  259.             aimDownSights.gunRoot.transform.rotation = aimDownSights.originalAngle;
  260.             aimDownSights.gunRoot.transform.position = aimDownSights.gunPos.transform.position;
  261.  
  262.             ObscuredPrefs.Set<int>(gunName + "_Ammo", ammoCount);
  263.  
  264.             GameManager.reloading = false;
  265.  
  266.             //aimDownSights.gunRoot = aimDownSights.gunPos;
  267.         }
  268.         IEnumerator FireCooldown()
  269.         {
  270.             canFire = false;
  271.             yield return new WaitForSeconds(fireRate);
  272.             canFire = true;
  273.         }
  274.         private void CastProjectileTrail()
  275.         {
  276.  
  277.             if (visualFromGun)
  278.             {
  279.                 trailObjectGun = bulletTrailPool.GetPooledBulletTrail(gameObject.transform.position, shootRotation);
  280.                 trailObjectGun.GetComponent<BulletModelSelection>().bulletToFire[bulletVisual].SetActive(true);
  281.                 trailObjectGun.GetComponent<Rigidbody>().AddForce(shootDirection * rangeProjectileSpeed, ForceMode.Force);
  282.             }
  283.             else
  284.             {
  285.                 trailObjectCam = bulletTrailPool.GetPooledBulletTrail(Camera.main.transform.position, shootRotation);
  286.                 trailObjectCam.GetComponent<BulletModelSelection>().bulletToFire[bulletVisual].SetActive(true);
  287.                 trailObjectCam.GetComponent<Rigidbody>().AddForce(shootDirection * rangeProjectileSpeed, ForceMode.Force);
  288.             }
  289.         }
  290.         private void CastBullet(GameObject bulletpos)
  291.         {
  292.             // Get an object from the pool and move it to a random position
  293.             GameObject proj = objectPool.GetObject();
  294.             proj.transform.position = bulletpos.transform.position;
  295.             proj.transform.rotation = shootRotation;
  296.             // Set the projectile's velocity
  297.             proj.GetComponent<Rigidbody>().AddForce(shootDirection * rangeProjectileSpeed, ForceMode.Force);
  298.             proj.GetComponent<BalisticProjectile>().initialVelocity = rangeProjectileSpeed;
  299.             if (useBulletTrail)
  300.             {
  301.                 CastProjectileTrail();
  302.             }
  303.  
  304.         }
  305.         private LayerMask otherMask;
  306.         private Quaternion shootRotation;
  307.         private Vector3 shootDirection;
  308.         private Vector3 barrel;
  309.         private GameObject trailObjectGun;
  310.         private GameObject trailObjectCam;
  311.         public void RangeAttack()
  312.         {
  313.             StartCoroutine(RecoilShake());
  314.             if (damageFromCamera)
  315.             {
  316.                 barrel = Camera.main.transform.position;
  317.             }
  318.             else
  319.             {
  320.                 barrel = nextRayCheckObj.transform.position;
  321.             }
  322.             origin = barrel; // Start position of the ray
  323.  
  324.  
  325.             direction = transform.forward; // Direction of the ray
  326.             distanceTraveled = 0f;
  327.  
  328.             // Get shoot direction with conditional spray based on shot count and auto mode
  329.             Vector3 sprayOffset = Vector3.zero;
  330.             if (shotsFired > accurateBulletOverrideCount)
  331.             {
  332.                 sprayOffset = Random.insideUnitSphere * sprayAmount;
  333.             }
  334.  
  335.  
  336.             if (damageFromCamera)
  337.             {
  338.                 //get shoot dir
  339.                 shootDirection = Camera.main.transform.forward + sprayOffset;
  340.             }
  341.             else
  342.             {
  343.                 //get shoot dir
  344.                 shootDirection = transform.forward + sprayOffset;
  345.  
  346.             }
  347.             shootDirection.Normalize();
  348.  
  349.             // Calculate the Quaternion rotation for the shoot direction
  350.             shootRotation = Quaternion.LookRotation(shootDirection);
  351.  
  352.             //play gunshot sound
  353.             //audioManager.PlayEffectClipAtPoint(shootclip, transform.position, volume);
  354.             audioSource.PlayOneShot(shootclip, volume);
  355.             //muzzle flash
  356.             muzzleFlashPooling.GetPooledMuzzleFlash(transform.position, transform.rotation);
  357.  
  358.  
  359.             //spend ammo
  360.             ObscuredPrefs.Set<int>(gunName + "_Ammo", ObscuredPrefs.Get<int>(gunName + "_Ammo") - 1);
  361.  
  362.             // Increment the number of shots fired
  363.             shotsFired++;
  364.             TriggerKickback();
  365.  
  366.             if (useProjectile)
  367.             {
  368.                 if (damageFromCamera)
  369.                 {
  370.                     if (useReplaceRay == false)
  371.                     {
  372.                         CastBullet(Camera.main.gameObject);
  373.                     }
  374.                     else
  375.                     {
  376.  
  377.                         // Define the ray. This will start at the game object's position and cast forward.
  378.                         Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
  379.  
  380.                         // Prepare a variable to store the hit information.
  381.                         RaycastHit hit;
  382.  
  383.                         // Cast the ray for a certain range and only against objects in the specified layerMask.
  384.                         if (Physics.Raycast(ray, out hit, replaceWithRayDistance, mask))
  385.                         {
  386.                             ApplyHit(hit);
  387.                             // Ray hit something, process the hit object.
  388.                             Debug.Log("Raycast hit: " + hit.collider.gameObject.name);
  389.                             if (useBulletTrail)
  390.                             {
  391.                                 CastProjectileTrail();
  392.                             }
  393.                         }
  394.                         else if (useReplaceRay == false)
  395.                         {
  396.  
  397.                             CastBullet(Camera.main.gameObject);
  398.                         }
  399.                     }
  400.  
  401.                 }
  402.                 else
  403.                 {
  404.                     if (useReplaceRay == false)
  405.                     {
  406.  
  407.  
  408.                             CastBullet(gameObject);
  409.                     }
  410.                     else
  411.                     {
  412.                         // Define the ray. This will start at the game object's position and cast forward.
  413.                         Ray ray = new Ray(transform.position, transform.forward);
  414.  
  415.                         // Prepare a variable to store the hit information.
  416.                         RaycastHit hit;
  417.  
  418.                         // Cast the ray for a certain range and only against objects in the specified layerMask.
  419.                         if (Physics.Raycast(ray, out hit, replaceWithRayDistance, mask))
  420.                         {
  421.                             ApplyHit(hit);
  422.                             // Ray hit something, process the hit object.
  423.                             Debug.Log("Raycast hit: " + hit.collider.gameObject.name);
  424.                             if (useBulletTrail)
  425.                             {
  426.                                 CastProjectileTrail();
  427.                             }
  428.                         }
  429.                         else
  430.                         {
  431.  
  432.  
  433.                             CastBullet(gameObject);
  434.                         }
  435.  
  436.                     }
  437.                 }
  438.             }
  439.             else
  440.             {
  441.  
  442.                 bulletShot = true;
  443.  
  444.                 StartCoroutine(ShootRayWithTravelTime());
  445.  
  446.  
  447.                 if (Physics.Raycast(barrel, shootDirection, out RaycastHit hit, range, mask))
  448.                 {
  449.                     if (hit.point != null)
  450.                     {
  451.                         if (useBulletTrail)
  452.                         {
  453.                             travelDistance = bulletSpeed * Time.deltaTime; // Calculate the distance the ray travels each frame
  454.                             GameObject trailObject = bulletTrailPool.GetPooledBulletTrail(transform.position, transform.rotation);
  455.                             trailObject.GetComponent<BulletModelSelection>().bulletToFire[bulletVisual].SetActive(true);
  456.                             trailObject.GetComponent<Rigidbody>().useGravity = false;
  457.                             //Destroy(trailObject.GetComponent<Rigidbody>());
  458.                             TrailRenderer trail = trailObject.GetComponent<TrailRenderer>(); // This line gets the TrailRenderer component
  459.                             StartCoroutine(SpawnTrail(trail, hit));
  460.  
  461.                         }
  462.                     }
  463.                 }
  464.                 else
  465.                 {
  466.                     if (useBulletTrail)
  467.                     {
  468.                         GameObject trailObject = bulletTrailPool.GetPooledBulletTrail(transform.position, transform.rotation);
  469.                         TrailRenderer trail = trailObject.GetComponent<TrailRenderer>(); // This line gets the TrailRenderer component
  470.                         trailObject.GetComponent<BulletModelSelection>().bulletToFire[bulletVisual].SetActive(true);
  471.                         trailObject.GetComponent<Rigidbody>().useGravity = false;
  472.                         //Destroy(trailObject.GetComponent<Rigidbody>());  
  473.                         Vector3 misseverything = transform.position + transform.forward * range;
  474.                         StartCoroutine(SpawnMissTrail(trail, misseverything));
  475.  
  476.                     }
  477.                 }
  478.             }
  479.         }
  480.         private float travelDistance;
  481.         private RaycastHit hitInfo;
  482.         private bool targetHit;
  483.         private Vector3 direction;
  484.         private Vector3 origin;
  485.         private float distanceTraveled;
  486.         IEnumerator ShootRayWithTravelTime()
  487.         {
  488.  
  489.  
  490.             while (bulletShot == true)
  491.             {
  492.                 travelDistance = bulletSpeed * Time.deltaTime; // Calculate the distance the ray travels each frame
  493.                 RaycastHit hit;
  494.                 //Debug.Log("serious fuckery");
  495.                 // Check if the ray hits something
  496.                 if (Physics.Raycast(origin, direction, out hit, travelDistance, mask))
  497.                 {
  498.                     //Debug.Log("Hit: " + hit.collider.name);  // Log the name of the hit object
  499.                     bulletShot = false;
  500.                     targetHit = true;
  501.                     hitInfo = hit; // Store the hit info for later
  502.  
  503.                     if (hit.collider.GetComponentInParent<Health>() != null)
  504.                     {
  505.  
  506.                         if (hit.collider.GetComponentInParent<Health>().currentHealthState == Health.HealthState.Enemy)
  507.                         {
  508.                             GameManager.enemyHit = true;
  509.                             //blood decal (wall)
  510.                             if (Physics.Raycast(barrel, shootDirection, out RaycastHit hit1, 15f, otherMask))
  511.                             {
  512.                                 // Generate a random Z rotation angle
  513.                                 float randomZRotation = Random.Range(0f, 360f);
  514.  
  515.                                 // Create a rotation that looks in the direction of the hit normal, then apply the random Z rotation
  516.                                 Quaternion rotation = Quaternion.LookRotation(hit1.normal) * Quaternion.Euler(0, 0, randomZRotation);
  517.  
  518.                                 bloodDecalPool.GetPooledDecalBlood(hit1.point, rotation);
  519.                             }
  520.  
  521.                             if (hit.collider.CompareTag("Enemy"))
  522.                             {
  523.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(minDamageToDo, maxDamageToDo + 1));
  524.                             }
  525.  
  526.                             if (hit.collider.CompareTag("EnemyHead"))
  527.                             {
  528.  
  529.                                 //Debug.Log("HEADSHOT");
  530.                                 // Calculate and apply damage
  531.                                 float min = minDamageToDo * headShotBuff;
  532.                                 float max = maxDamageToDo * headShotBuff;
  533.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  534.  
  535.  
  536.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  537.                                 {
  538.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  539.                                     {
  540.                                         hit.collider.GetComponentInParent<DismembermenSettings>().headObj.SetActive(false);
  541.                                         hit.collider.GetComponentInParent<DismembermenSettings>().headBox.SetActive(false);
  542.                                     }
  543.                                 }
  544.  
  545.                             }
  546.  
  547.                             if (hit.collider.CompareTag("EnemyRightHand"))
  548.                             {
  549.                                 float min = minDamageToDo / handPenalty;
  550.                                 float max = maxDamageToDo / handPenalty;
  551.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  552.                                 // Loop through each element in the bodyParts array
  553.  
  554.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  555.                                 {
  556.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  557.                                     {
  558.                                         hit.collider.GetComponentInParent<DismembermenSettings>().rHandObj.SetActive(false);
  559.                                         hit.collider.GetComponentInParent<DismembermenSettings>().rHandBox.SetActive(false);
  560.                                     }
  561.                                 }
  562.                             }
  563.  
  564.                             if (hit.collider.CompareTag("EnemyRightUpperArm"))
  565.                             {
  566.                                 float min = minDamageToDo / armPenalty;
  567.                                 float max = maxDamageToDo / armPenalty;
  568.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  569.                                 // Loop through each element in the bodyParts array
  570.  
  571.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  572.                                 {
  573.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  574.                                     {
  575.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmObj.activeInHierarchy == false)
  576.                                         {
  577.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rUpperArmObj.SetActive(false);
  578.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rUpperArmBox.SetActive(false);
  579.                                         }
  580.                                     }
  581.                                 }
  582.                             }
  583.  
  584.                             if (hit.collider.CompareTag("EnemyRightForeArm"))
  585.                             {
  586.                                 float min = minDamageToDo / armPenalty;
  587.                                 float max = maxDamageToDo / armPenalty;
  588.  
  589.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  590.                                 // Loop through each element in the bodyParts array
  591.  
  592.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  593.                                 {
  594.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  595.                                     {
  596.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().rHandObj.activeInHierarchy == false)
  597.                                         {
  598.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmObj.SetActive(false);
  599.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmBox.SetActive(false);
  600.                                         }
  601.                                     }
  602.                                 }
  603.  
  604.                             }
  605.  
  606.                             if (hit.collider.CompareTag("EnemyLeftHand"))
  607.                             {
  608.                                 float min = minDamageToDo / handPenalty;
  609.                                 float max = maxDamageToDo / handPenalty;
  610.  
  611.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  612.  
  613.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  614.                                 {
  615.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  616.                                     {
  617.                                         hit.collider.GetComponentInParent<DismembermenSettings>().lHandObj.SetActive(false);
  618.                                         hit.collider.GetComponentInParent<DismembermenSettings>().lHandBox.SetActive(false);
  619.                                     }
  620.                                 }
  621.  
  622.                             }
  623.  
  624.                             if (hit.collider.CompareTag("EnemyLeftForeArm"))
  625.                             {
  626.                                 float min = minDamageToDo / armPenalty;
  627.                                 float max = maxDamageToDo / armPenalty;
  628.  
  629.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  630.                                 // Loop through each element in the bodyParts array
  631.  
  632.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  633.                                 {
  634.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  635.                                     {
  636.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().lHandObj.activeInHierarchy == false)
  637.                                         {
  638.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmObj.SetActive(false);
  639.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmBox.SetActive(false);
  640.                                         }
  641.                                     }
  642.                                 }
  643.                             }
  644.  
  645.                             if (hit.collider.CompareTag("EnemyLeftUpperArm"))
  646.                             {
  647.                                 float min = minDamageToDo / armPenalty;
  648.                                 float max = maxDamageToDo / armPenalty;
  649.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  650.                                 // Loop through each element in the bodyParts array
  651.  
  652.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  653.                                 {
  654.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  655.                                     {
  656.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmObj.activeInHierarchy == false)
  657.                                         {
  658.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lUpperArmObj.SetActive(false);
  659.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lUpperArmBox.SetActive(false);
  660.                                         }
  661.                                     }
  662.                                 }
  663.                             }
  664.  
  665.                             if (hit.collider.CompareTag("EnemyRightFoot"))
  666.                             {
  667.                                 //Debug.Log("RIGHT FOOT HIT");
  668.                                 float min = minDamageToDo / footPenalty;
  669.                                 float max = maxDamageToDo / footPenalty;
  670.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  671.                                 // Loop through each element in the bodyParts array
  672.  
  673.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  674.                                 {
  675.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  676.                                     {
  677.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().usingRightShoe)
  678.                                         {
  679.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rShoeObj.SetActive(false);
  680.                                         }
  681.                                         hit.collider.GetComponentInParent<DismembermenSettings>().rFootObj.SetActive(false);
  682.                                         hit.collider.GetComponentInParent<DismembermenSettings>().rFootBox.SetActive(false);
  683.                                     }
  684.                                 }
  685.                             }
  686.  
  687.                             if (hit.collider.CompareTag("EnemyRightLowerLeg"))
  688.                             {
  689.                                 float min = minDamageToDo / legPenalty;
  690.                                 float max = maxDamageToDo / legPenalty;
  691.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  692.                                 // Loop through each element in the bodyParts array
  693.  
  694.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  695.                                 {
  696.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  697.                                     {
  698.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().rFootObj.activeInHierarchy == false)
  699.                                         {
  700.  
  701.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegObj.SetActive(false);
  702.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegBox.SetActive(false);
  703.                                         }
  704.  
  705.                                     }
  706.                                 }
  707.  
  708.                             }
  709.  
  710.                             if (hit.collider.CompareTag("EnemyRightUpperLeg"))
  711.                             {
  712.                                 float min = minDamageToDo / legPenalty;
  713.                                 float max = maxDamageToDo / legPenalty;
  714.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  715.                                 // Loop through each element in the bodyParts array
  716.  
  717.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  718.                                 {
  719.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  720.                                     {
  721.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegObj.activeInHierarchy == false)
  722.                                         {
  723.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rUpperLegObj.SetActive(false);
  724.                                             hit.collider.GetComponentInParent<DismembermenSettings>().rUpperLegBox.SetActive(false);
  725.                                         }
  726.  
  727.                                     }
  728.                                 }
  729.                             }
  730.  
  731.                             if (hit.collider.CompareTag("EnemyLeftFoot"))
  732.                             {
  733.                                 //Debug.Log("LEFT FOOT HIT");
  734.                                 float min = minDamageToDo / footPenalty;
  735.                                 float max = maxDamageToDo / footPenalty;
  736.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  737.                                 // Loop through each element in the bodyParts array
  738.  
  739.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  740.                                 {
  741.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  742.                                     {
  743.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().usingRightShoe)
  744.                                         {
  745.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lShoeObj.SetActive(false);
  746.                                         }
  747.                                         hit.collider.GetComponentInParent<DismembermenSettings>().lFootObj.SetActive(false);
  748.                                         hit.collider.GetComponentInParent<DismembermenSettings>().lFootBox.SetActive(false);
  749.                                     }
  750.                                 }
  751.                             }
  752.  
  753.  
  754.                             if (hit.collider.CompareTag("EnemyLeftLowerLeg"))
  755.                             {
  756.                                 float min = minDamageToDo / legPenalty;
  757.                                 float max = maxDamageToDo / legPenalty;
  758.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  759.                                 // Loop through each element in the bodyParts array
  760.  
  761.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  762.                                 {
  763.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  764.                                     {
  765.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().lFootObj.activeInHierarchy == false)
  766.                                         {
  767.  
  768.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegObj.SetActive(false);
  769.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegBox.SetActive(false);
  770.                                         }
  771.  
  772.                                     }
  773.                                 }
  774.                             }
  775.  
  776.                             if (hit.collider.CompareTag("EnemyLeftUpperLeg"))
  777.                             {
  778.                                 float min = minDamageToDo / legPenalty;
  779.                                 float max = maxDamageToDo / legPenalty;
  780.                                 hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  781.                                 // Loop through each element in the bodyParts array
  782.  
  783.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  784.                                 {
  785.                                     if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  786.                                     {
  787.                                         if (hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegObj.activeInHierarchy == false)
  788.                                         {
  789.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lUpperLegObj.SetActive(false);
  790.                                             hit.collider.GetComponentInParent<DismembermenSettings>().lUpperLegBox.SetActive(false);
  791.                                         }
  792.  
  793.                                     }
  794.                                 }
  795.                             }
  796.                         }
  797.  
  798.  
  799.                     }
  800.  
  801.                     Debug.DrawLine(transform.position, hit.point, Color.yellow, 1f);
  802.  
  803.                 }
  804.  
  805.                 // Move the origin of the ray forward
  806.                 origin += direction * travelDistance;
  807.                 distanceTraveled += travelDistance;
  808.                 yield return null; // Wait until the next frame
  809.             }
  810.             // After the bullet has visually reached the target, apply damage
  811.             if (targetHit)
  812.             {
  813.                 //ApplyDamage(hitInfo);
  814.             }
  815.         }
  816.         //HITSCAN
  817.         public void ApplyHit(RaycastHit hit, GameObject bulletObj = null)
  818.         {
  819.             //Decrease health of object by calculatedDamage
  820.             if (hit.collider.GetComponent<ObjectHealth>())
  821.                 hit.collider.GetComponent<ObjectHealth>().health -= Random.Range(minDamageToDo, maxDamageToDo + 1);
  822.  
  823.  
  824.             if (hit.collider.GetComponentInParent<Health>())
  825.             {
  826.                 if (hit.collider.GetComponentInParent<Health>().currentHealthState == Health.HealthState.Enemy)
  827.                 {
  828.                     //Debug.Log("hitting enemy second with ray");
  829.                     GameManager.enemyHit = true;
  830.                     enemyHit = true;
  831.                     if (hit.collider.CompareTag("Enemy"))
  832.                     {
  833.  
  834.                         // Calculate and apply damage
  835.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(minDamageToDo, maxDamageToDo + 1));
  836.  
  837.                         // Handle blood hit effects
  838.                         DoBlood(hit);
  839.  
  840.                         if (bulletObj != null)
  841.                         {
  842.                             objectPool.ReturnObject(bulletObj);
  843.                         }
  844.  
  845.  
  846.                         // Since we've hit an enemy, we don't need to check other colliders
  847.                         //break;
  848.                     }
  849.                     else if (hit.collider.CompareTag("EnemyHead"))
  850.                     {
  851.  
  852.                         // Calculate and apply damage
  853.                         float min = minDamageToDo * headShotBuff;
  854.                         float max = maxDamageToDo * headShotBuff;
  855.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  856.  
  857.  
  858.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  859.                         {
  860.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  861.                             {
  862.                                 hit.collider.GetComponentInParent<DismembermenSettings>().headObj.SetActive(false);
  863.                                 hit.collider.GetComponentInParent<DismembermenSettings>().headBox.SetActive(false);
  864.                             }
  865.                         }
  866.  
  867.                         // Handle blood hit effects
  868.                         DoBlood(hit);
  869.                         if (bulletObj != null)
  870.                         {
  871.                             objectPool.ReturnObject(bulletObj);
  872.                         }
  873.                     }
  874.                     else if (hit.collider.CompareTag("EnemyRightHand"))
  875.                     {
  876.  
  877.                         float min = minDamageToDo / handPenalty;
  878.                         float max = maxDamageToDo / handPenalty;
  879.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  880.                         // Loop through each element in the bodyParts array
  881.  
  882.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  883.                         {
  884.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  885.                             {
  886.                                 hit.collider.GetComponentInParent<DismembermenSettings>().rHandObj.SetActive(false);
  887.                                 hit.collider.GetComponentInParent<DismembermenSettings>().rHandBox.SetActive(false);
  888.                             }
  889.                         }
  890.  
  891.                         DoBlood(hit);
  892.                         if (bulletObj != null)
  893.                         {
  894.                             objectPool.ReturnObject(bulletObj);
  895.                         }
  896.                         //Destroy(gameObject);
  897.                     }
  898.                     else if (hit.collider.CompareTag("EnemyRightForeArm"))
  899.                     {
  900.  
  901.                         float min = minDamageToDo / armPenalty;
  902.                         float max = maxDamageToDo / armPenalty;
  903.  
  904.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  905.                         // Loop through each element in the bodyParts array
  906.  
  907.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  908.                         {
  909.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  910.                             {
  911.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().rHandObj.activeInHierarchy == false)
  912.                                 {
  913.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmObj.SetActive(false);
  914.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmBox.SetActive(false);
  915.                                 }
  916.                             }
  917.                         }
  918.  
  919.                         DoBlood(hit);
  920.                         if (bulletObj != null)
  921.                         {
  922.                             objectPool.ReturnObject(bulletObj);
  923.                         }
  924.  
  925.                     }
  926.                     else if (hit.collider.CompareTag("EnemyRightUpperArm"))
  927.                     {
  928.                         float min = minDamageToDo / armPenalty;
  929.                         float max = maxDamageToDo / armPenalty;
  930.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  931.                         // Loop through each element in the bodyParts array
  932.  
  933.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  934.                         {
  935.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  936.                             {
  937.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmObj.activeInHierarchy == false)
  938.                                 {
  939.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rUpperArmObj.SetActive(false);
  940.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rUpperArmBox.SetActive(false);
  941.                                 }
  942.                             }
  943.                         }
  944.                         DoBlood(hit);
  945.                         if (bulletObj != null)
  946.                         {
  947.                             objectPool.ReturnObject(bulletObj);
  948.                         }
  949.  
  950.                     }
  951.                     else if (hit.collider.CompareTag("EnemyLeftHand"))
  952.                     {
  953.  
  954.                         float min = minDamageToDo / handPenalty;
  955.                         float max = maxDamageToDo / handPenalty;
  956.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  957.                         // Loop through each element in the bodyParts array
  958.  
  959.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  960.                         {
  961.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  962.                             {
  963.                                 hit.collider.GetComponentInParent<DismembermenSettings>().lHandObj.SetActive(false);
  964.                                 hit.collider.GetComponentInParent<DismembermenSettings>().lHandBox.SetActive(false);
  965.                             }
  966.                         }
  967.  
  968.                         DoBlood(hit);
  969.                         if (bulletObj != null)
  970.                         {
  971.                             objectPool.ReturnObject(bulletObj);
  972.                         }
  973.  
  974.                         //Destroy(gameObject);
  975.                     }
  976.                     else if (hit.collider.CompareTag("EnemyLeftForeArm"))
  977.                     {
  978.                         float min = minDamageToDo / armPenalty;
  979.                         float max = maxDamageToDo / armPenalty;
  980.  
  981.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  982.                         // Loop through each element in the bodyParts array
  983.  
  984.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  985.                         {
  986.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  987.                             {
  988.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().lHandObj.activeInHierarchy == false)
  989.                                 {
  990.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmObj.SetActive(false);
  991.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmBox.SetActive(false);
  992.                                 }
  993.                             }
  994.                         }
  995.  
  996.                         DoBlood(hit);
  997.                         if (bulletObj != null)
  998.                         {
  999.                             objectPool.ReturnObject(bulletObj);
  1000.                         }
  1001.  
  1002.                     }
  1003.                     else if (hit.collider.CompareTag("EnemyLeftUpperArm"))
  1004.                     {
  1005.                         float min = minDamageToDo / armPenalty;
  1006.                         float max = maxDamageToDo / armPenalty;
  1007.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1008.                         // Loop through each element in the bodyParts array
  1009.  
  1010.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  1011.                         {
  1012.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1013.                             {
  1014.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmObj.activeInHierarchy == false)
  1015.                                 {
  1016.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lUpperArmObj.SetActive(false);
  1017.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lUpperArmBox.SetActive(false);
  1018.                                 }
  1019.                             }
  1020.                         }
  1021.                         DoBlood(hit);
  1022.                         if (bulletObj != null)
  1023.                         {
  1024.                             objectPool.ReturnObject(bulletObj);
  1025.                         }
  1026.  
  1027.                     }
  1028.                     else if (hit.collider.CompareTag("EnemyRightFoot"))
  1029.                     {
  1030.                         float min = minDamageToDo / footPenalty;
  1031.                         float max = maxDamageToDo / footPenalty;
  1032.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1033.                         // Loop through each element in the bodyParts array
  1034.  
  1035.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  1036.                         {
  1037.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1038.                             {
  1039.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().usingRightShoe)
  1040.                                 {
  1041.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rShoeObj.SetActive(false);
  1042.                                 }
  1043.                                 hit.collider.GetComponentInParent<DismembermenSettings>().rFootObj.SetActive(false);
  1044.                                 hit.collider.GetComponentInParent<DismembermenSettings>().rFootBox.SetActive(false);
  1045.                             }
  1046.                         }
  1047.  
  1048.                         DoBlood(hit);
  1049.                         if (bulletObj != null)
  1050.                         {
  1051.                             objectPool.ReturnObject(bulletObj);
  1052.                         }
  1053.  
  1054.                     }
  1055.                     else if (hit.collider.CompareTag("EnemyRightLowerLeg"))
  1056.                     {
  1057.                         float min = minDamageToDo / legPenalty;
  1058.                         float max = maxDamageToDo / legPenalty;
  1059.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1060.                         // Loop through each element in the bodyParts array
  1061.  
  1062.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  1063.                         {
  1064.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1065.                             {
  1066.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().rFootObj.activeInHierarchy == false)
  1067.                                 {
  1068.  
  1069.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegObj.SetActive(false);
  1070.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegBox.SetActive(false);
  1071.                                 }
  1072.  
  1073.                             }
  1074.                         }
  1075.  
  1076.                         DoBlood(hit);
  1077.                         if (bulletObj != null)
  1078.                         {
  1079.                             objectPool.ReturnObject(bulletObj);
  1080.                         }
  1081.  
  1082.                     }
  1083.                     else if (hit.collider.CompareTag("EnemyRightUpperLeg"))
  1084.                     {
  1085.                         float min = minDamageToDo / legPenalty;
  1086.                         float max = maxDamageToDo / legPenalty;
  1087.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1088.                         // Loop through each element in the bodyParts array
  1089.  
  1090.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  1091.                         {
  1092.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1093.                             {
  1094.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegObj.activeInHierarchy == false)
  1095.                                 {
  1096.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rUpperLegObj.SetActive(false);
  1097.                                     hit.collider.GetComponentInParent<DismembermenSettings>().rUpperLegBox.SetActive(false);
  1098.                                 }
  1099.  
  1100.                             }
  1101.                         }
  1102.  
  1103.                         DoBlood(hit);
  1104.                         if (bulletObj != null)
  1105.                         {
  1106.                             objectPool.ReturnObject(bulletObj);
  1107.                         }
  1108.  
  1109.                     }
  1110.                     else if (hit.collider.CompareTag("EnemyLeftFoot"))
  1111.                     {
  1112.                         float min = minDamageToDo / footPenalty;
  1113.                         float max = maxDamageToDo / footPenalty;
  1114.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1115.                         // Loop through each element in the bodyParts array
  1116.  
  1117.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  1118.                         {
  1119.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1120.                             {
  1121.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().usingRightShoe)
  1122.                                 {
  1123.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lShoeObj.SetActive(false);
  1124.                                 }
  1125.                                 hit.collider.GetComponentInParent<DismembermenSettings>().lFootObj.SetActive(false);
  1126.                                 hit.collider.GetComponentInParent<DismembermenSettings>().lFootBox.SetActive(false);
  1127.                             }
  1128.                         }
  1129.  
  1130.                         DoBlood(hit);
  1131.                         if (bulletObj != null)
  1132.                         {
  1133.                             objectPool.ReturnObject(bulletObj);
  1134.                         }
  1135.  
  1136.                     }
  1137.                     else if (hit.collider.CompareTag("EnemyLeftLowerLeg"))
  1138.                     {
  1139.  
  1140.                         float min = minDamageToDo / legPenalty;
  1141.                         float max = maxDamageToDo / legPenalty;
  1142.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1143.                         // Loop through each element in the bodyParts array
  1144.  
  1145.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  1146.                         {
  1147.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1148.                             {
  1149.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().lFootObj.activeInHierarchy == false)
  1150.                                 {
  1151.  
  1152.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegObj.SetActive(false);
  1153.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegBox.SetActive(false);
  1154.                                 }
  1155.  
  1156.                             }
  1157.                         }
  1158.  
  1159.                         DoBlood(hit);
  1160.                         if (bulletObj != null)
  1161.                         {
  1162.                             objectPool.ReturnObject(bulletObj);
  1163.                         }
  1164.  
  1165.                     }
  1166.                     else if (hit.collider.CompareTag("EnemyLeftUpperLeg"))
  1167.                     {
  1168.                         float min = minDamageToDo / legPenalty;
  1169.                         float max = maxDamageToDo / legPenalty;
  1170.                         hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1171.                         // Loop through each element in the bodyParts array
  1172.  
  1173.                         if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
  1174.                         {
  1175.                             if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1176.                             {
  1177.                                 if (hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegObj.activeInHierarchy == false)
  1178.                                 {
  1179.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lUpperLegObj.SetActive(false);
  1180.                                     hit.collider.GetComponentInParent<DismembermenSettings>().lUpperLegBox.SetActive(false);
  1181.                                 }
  1182.  
  1183.                             }
  1184.                         }
  1185.  
  1186.                         bloodHitPool.GetPooledBloodHit(hit.collider.transform.position, Quaternion.LookRotation(hit.normal));
  1187.                         if (bulletObj != null)
  1188.                         {
  1189.                             objectPool.ReturnObject(bulletObj);
  1190.                         }
  1191.  
  1192.                     }
  1193.  
  1194.                 }
  1195.  
  1196.             }
  1197.             else
  1198.             {
  1199.                 if (enemyHit == false)
  1200.                 {
  1201.                     missHitPool.GetPooledMissHit(hit.point, Quaternion.LookRotation(hit.normal));
  1202.                 }
  1203.                 else
  1204.                 {
  1205.                     enemyHit = false;
  1206.                 }
  1207.             }
  1208.  
  1209.             /*
  1210.             if (hit.collider.CompareTag("Untagged"))
  1211.             {
  1212.                 objectPool.ReturnObject(bulletObj);
  1213.                 //StartCoroutine(ABC(bulletObj));
  1214.  
  1215.             }
  1216.             */
  1217.         }
  1218.         void DoBlood(RaycastHit hit)
  1219.         {
  1220.  
  1221.             bloodHitPool.GetPooledBloodHit(hit.collider.transform.position, Quaternion.LookRotation(hit.normal));
  1222.         }
  1223.         //PROJECITLE HIT
  1224.         public void TakeHit(Collider hit, GameObject bulletObj)
  1225.         {
  1226.             //Decrease health of object by calculatedDamage
  1227.             if (hit.GetComponent<ObjectHealth>())
  1228.                 hit.GetComponent<ObjectHealth>().health -= Random.Range(minDamageToDo, maxDamageToDo + 1);
  1229.  
  1230.  
  1231.             if (hit.GetComponentInParent<Health>())
  1232.             {
  1233.                 if (hit.GetComponentInParent<Health>().currentHealthState == Health.HealthState.Enemy)
  1234.                 {
  1235.                     GameManager.enemyHit = true;
  1236.                     enemyHit = true;
  1237.                     if (hit.CompareTag("Enemy"))
  1238.                     {
  1239.  
  1240.                         // Calculate and apply damage
  1241.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(minDamageToDo, maxDamageToDo + 1));
  1242.  
  1243.                         // Handle blood hit effects
  1244.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1245.                         objectPool.ReturnObject(bulletObj);
  1246.  
  1247.  
  1248.                         // Since we've hit an enemy, we don't need to check other colliders
  1249.                         //break;
  1250.                     }
  1251.                     else if (hit.CompareTag("EnemyHead"))
  1252.                     {
  1253.  
  1254.                         // Calculate and apply damage
  1255.                         float min = minDamageToDo * headShotBuff;
  1256.                         float max = maxDamageToDo * headShotBuff;
  1257.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1258.  
  1259.  
  1260.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1261.                         {
  1262.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1263.                             {
  1264.                                 hit.GetComponentInParent<DismembermenSettings>().headObj.SetActive(false);
  1265.                                 hit.GetComponentInParent<DismembermenSettings>().headBox.SetActive(false);
  1266.                             }
  1267.                         }
  1268.  
  1269.                         // Handle blood hit effects
  1270.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1271.                         objectPool.ReturnObject(bulletObj);
  1272.                         //objectPool.ReturnObject(bulletObj);
  1273.  
  1274.                         // Return the projectile to the object pool
  1275.                         Debug.Log("headshot");
  1276.                         // Since we've hit an enemy, we don't need to check other colliders
  1277.                         //break;
  1278.                     }
  1279.                     else if (hit.CompareTag("EnemyRightHand"))
  1280.                     {
  1281.  
  1282.                         float min = minDamageToDo / handPenalty;
  1283.                         float max = maxDamageToDo / handPenalty;
  1284.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1285.                         // Loop through each element in the bodyParts array
  1286.  
  1287.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1288.                         {
  1289.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1290.                             {
  1291.                                 hit.GetComponentInParent<DismembermenSettings>().rHandObj.SetActive(false);
  1292.                                 hit.GetComponentInParent<DismembermenSettings>().rHandBox.SetActive(false);
  1293.                             }
  1294.                         }
  1295.  
  1296.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1297.                         objectPool.ReturnObject(bulletObj);
  1298.                         //Destroy(gameObject);
  1299.                     }
  1300.                     else if (hit.CompareTag("EnemyRightForeArm"))
  1301.                     {
  1302.  
  1303.                         float min = minDamageToDo / armPenalty;
  1304.                         float max = maxDamageToDo / armPenalty;
  1305.  
  1306.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1307.                         // Loop through each element in the bodyParts array
  1308.  
  1309.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1310.                         {
  1311.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1312.                             {
  1313.                                 if (hit.GetComponentInParent<DismembermenSettings>().rHandObj.activeInHierarchy == false)
  1314.                                 {
  1315.                                     hit.GetComponentInParent<DismembermenSettings>().rForeArmObj.SetActive(false);
  1316.                                     hit.GetComponentInParent<DismembermenSettings>().rForeArmBox.SetActive(false);
  1317.                                 }
  1318.                             }
  1319.                         }
  1320.  
  1321.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1322.                         objectPool.ReturnObject(bulletObj);
  1323.  
  1324.                     }
  1325.                     else if (hit.CompareTag("EnemyRightUpperArm"))
  1326.                     {
  1327.                         float min = minDamageToDo / armPenalty;
  1328.                         float max = maxDamageToDo / armPenalty;
  1329.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1330.                         // Loop through each element in the bodyParts array
  1331.  
  1332.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1333.                         {
  1334.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1335.                             {
  1336.                                 if (hit.GetComponentInParent<DismembermenSettings>().rForeArmObj.activeInHierarchy == false)
  1337.                                 {
  1338.                                     hit.GetComponentInParent<DismembermenSettings>().rUpperArmObj.SetActive(false);
  1339.                                     hit.GetComponentInParent<DismembermenSettings>().rUpperArmBox.SetActive(false);
  1340.                                 }
  1341.                             }
  1342.                         }
  1343.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1344.                         objectPool.ReturnObject(bulletObj);
  1345.  
  1346.                     }
  1347.                     else if (hit.CompareTag("EnemyLeftHand"))
  1348.                     {
  1349.  
  1350.                         float min = minDamageToDo / handPenalty;
  1351.                         float max = maxDamageToDo / handPenalty;
  1352.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1353.                         // Loop through each element in the bodyParts array
  1354.  
  1355.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1356.                         {
  1357.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1358.                             {
  1359.                                 hit.GetComponentInParent<DismembermenSettings>().lHandObj.SetActive(false);
  1360.                                 hit.GetComponentInParent<DismembermenSettings>().lHandBox.SetActive(false);
  1361.                             }
  1362.                         }
  1363.  
  1364.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1365.                         objectPool.ReturnObject(bulletObj);
  1366.  
  1367.                         //Destroy(gameObject);
  1368.                     }
  1369.                     else if (hit.CompareTag("EnemyLeftForeArm"))
  1370.                     {
  1371.                         float min = minDamageToDo / armPenalty;
  1372.                         float max = maxDamageToDo / armPenalty;
  1373.  
  1374.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1375.                         // Loop through each element in the bodyParts array
  1376.  
  1377.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1378.                         {
  1379.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1380.                             {
  1381.                                 if (hit.GetComponentInParent<DismembermenSettings>().lHandObj.activeInHierarchy == false)
  1382.                                 {
  1383.                                     hit.GetComponentInParent<DismembermenSettings>().lForeArmObj.SetActive(false);
  1384.                                     hit.GetComponentInParent<DismembermenSettings>().lForeArmBox.SetActive(false);
  1385.                                 }
  1386.                             }
  1387.                         }
  1388.  
  1389.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1390.                         objectPool.ReturnObject(bulletObj);
  1391.  
  1392.                     }
  1393.                     else if (hit.CompareTag("EnemyLeftUpperArm"))
  1394.                     {
  1395.                         float min = minDamageToDo / armPenalty;
  1396.                         float max = maxDamageToDo / armPenalty;
  1397.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1398.                         // Loop through each element in the bodyParts array
  1399.  
  1400.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1401.                         {
  1402.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1403.                             {
  1404.                                 if (hit.GetComponentInParent<DismembermenSettings>().lForeArmObj.activeInHierarchy == false)
  1405.                                 {
  1406.                                     hit.GetComponentInParent<DismembermenSettings>().lUpperArmObj.SetActive(false);
  1407.                                     hit.GetComponentInParent<DismembermenSettings>().lUpperArmBox.SetActive(false);
  1408.                                 }
  1409.                             }
  1410.                         }
  1411.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1412.                         objectPool.ReturnObject(bulletObj);
  1413.  
  1414.                     }
  1415.                     else if (hit.CompareTag("EnemyRightFoot"))
  1416.                     {
  1417.                         float min = minDamageToDo / footPenalty;
  1418.                         float max = maxDamageToDo / footPenalty;
  1419.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1420.                         // Loop through each element in the bodyParts array
  1421.  
  1422.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1423.                         {
  1424.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1425.                             {
  1426.                                 if (hit.GetComponentInParent<DismembermenSettings>().usingRightShoe)
  1427.                                 {
  1428.                                     hit.GetComponentInParent<DismembermenSettings>().rShoeObj.SetActive(false);
  1429.                                 }
  1430.                                 hit.GetComponentInParent<DismembermenSettings>().rFootObj.SetActive(false);
  1431.                                 hit.GetComponentInParent<DismembermenSettings>().rFootBox.SetActive(false);
  1432.                             }
  1433.                         }
  1434.  
  1435.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1436.                         objectPool.ReturnObject(bulletObj);
  1437.  
  1438.                     }
  1439.                     else if (hit.CompareTag("EnemyRightLowerLeg"))
  1440.                     {
  1441.                         float min = minDamageToDo / legPenalty;
  1442.                         float max = maxDamageToDo / legPenalty;
  1443.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1444.                         // Loop through each element in the bodyParts array
  1445.  
  1446.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1447.                         {
  1448.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1449.                             {
  1450.                                 if (hit.GetComponentInParent<DismembermenSettings>().rFootObj.activeInHierarchy == false)
  1451.                                 {
  1452.  
  1453.                                     hit.GetComponentInParent<DismembermenSettings>().rLowerLegObj.SetActive(false);
  1454.                                     hit.GetComponentInParent<DismembermenSettings>().rLowerLegBox.SetActive(false);
  1455.                                 }
  1456.  
  1457.                             }
  1458.                         }
  1459.  
  1460.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1461.                         objectPool.ReturnObject(bulletObj);
  1462.  
  1463.                     }
  1464.                     else if (hit.CompareTag("EnemyRightUpperLeg"))
  1465.                     {
  1466.                         float min = minDamageToDo / legPenalty;
  1467.                         float max = maxDamageToDo / legPenalty;
  1468.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1469.                         // Loop through each element in the bodyParts array
  1470.  
  1471.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1472.                         {
  1473.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1474.                             {
  1475.                                 if (hit.GetComponentInParent<DismembermenSettings>().rLowerLegObj.activeInHierarchy == false)
  1476.                                 {
  1477.                                     hit.GetComponentInParent<DismembermenSettings>().rUpperLegObj.SetActive(false);
  1478.                                     hit.GetComponentInParent<DismembermenSettings>().rUpperLegBox.SetActive(false);
  1479.                                 }
  1480.  
  1481.                             }
  1482.                         }
  1483.  
  1484.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1485.                         objectPool.ReturnObject(bulletObj);
  1486.  
  1487.                     }
  1488.                     else if (hit.CompareTag("EnemyLeftFoot"))
  1489.                     {
  1490.                         float min = minDamageToDo / footPenalty;
  1491.                         float max = maxDamageToDo / footPenalty;
  1492.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1493.                         // Loop through each element in the bodyParts array
  1494.  
  1495.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1496.                         {
  1497.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1498.                             {
  1499.                                 if (hit.GetComponentInParent<DismembermenSettings>().usingRightShoe)
  1500.                                 {
  1501.                                     hit.GetComponentInParent<DismembermenSettings>().lShoeObj.SetActive(false);
  1502.                                 }
  1503.                                 hit.GetComponentInParent<DismembermenSettings>().lFootObj.SetActive(false);
  1504.                                 hit.GetComponentInParent<DismembermenSettings>().lFootBox.SetActive(false);
  1505.                             }
  1506.                         }
  1507.  
  1508.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1509.                         objectPool.ReturnObject(bulletObj);
  1510.  
  1511.                     }
  1512.                     else if (hit.CompareTag("EnemyLeftLowerLeg"))
  1513.                     {
  1514.  
  1515.                         float min = minDamageToDo / legPenalty;
  1516.                         float max = maxDamageToDo / legPenalty;
  1517.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1518.                         // Loop through each element in the bodyParts array
  1519.  
  1520.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1521.                         {
  1522.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1523.                             {
  1524.                                 if (hit.GetComponentInParent<DismembermenSettings>().lFootObj.activeInHierarchy == false)
  1525.                                 {
  1526.  
  1527.                                     hit.GetComponentInParent<DismembermenSettings>().lLowerLegObj.SetActive(false);
  1528.                                     hit.GetComponentInParent<DismembermenSettings>().lLowerLegBox.SetActive(false);
  1529.                                 }
  1530.  
  1531.                             }
  1532.                         }
  1533.  
  1534.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1535.                         objectPool.ReturnObject(bulletObj);
  1536.  
  1537.                     }
  1538.                     else if (hit.CompareTag("EnemyLeftUpperLeg"))
  1539.                     {
  1540.                         float min = minDamageToDo / legPenalty;
  1541.                         float max = maxDamageToDo / legPenalty;
  1542.                         hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
  1543.                         // Loop through each element in the bodyParts array
  1544.  
  1545.                         if (hit.GetComponentInParent<DismembermenSettings>() != null)
  1546.                         {
  1547.                             if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
  1548.                             {
  1549.                                 if (hit.GetComponentInParent<DismembermenSettings>().lLowerLegObj.activeInHierarchy == false)
  1550.                                 {
  1551.                                     hit.GetComponentInParent<DismembermenSettings>().lUpperLegObj.SetActive(false);
  1552.                                     hit.GetComponentInParent<DismembermenSettings>().lUpperLegBox.SetActive(false);
  1553.                                 }
  1554.  
  1555.                             }
  1556.                         }
  1557.  
  1558.                         bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
  1559.                         objectPool.ReturnObject(bulletObj);
  1560.  
  1561.                     }
  1562.  
  1563.                 }
  1564.  
  1565.             }
  1566.             /*
  1567.             else
  1568.             {
  1569.                 if (enemyHit == false)
  1570.                 {
  1571.  
  1572.                 }
  1573.                 else
  1574.                 {
  1575.                     enemyHit = false;
  1576.                 }
  1577.             }
  1578.  
  1579.             if (hit.collider.CompareTag("Untagged"))
  1580.             {
  1581.                 objectPool.ReturnObject(bulletObj);
  1582.                 //StartCoroutine(ABC(bulletObj));
  1583.  
  1584.             }
  1585.             */
  1586.         }
  1587.         private IEnumerator SpawnMissTrail(TrailRenderer trail, Vector3 miss)
  1588.         {
  1589.             float time = 0;
  1590.             Vector3 startpos = trail.transform.position;
  1591.  
  1592.             while (time < 0.1f)
  1593.             {
  1594.                 trail.transform.position = Vector3.Lerp(startpos, miss, time);
  1595.  
  1596.                 time += Time.deltaTime / 0.5f;
  1597.  
  1598.                 yield return null;
  1599.             }
  1600.             trail.transform.position = miss;
  1601.         }
  1602.         private IEnumerator SpawnTrail(TrailRenderer Trail, RaycastHit hit)
  1603.         {
  1604.             Vector3 startPosition = Trail.transform.position;
  1605.             Vector3 direction = (hit.point - Trail.transform.position).normalized;
  1606.  
  1607.             float distance = Vector3.Distance(Trail.transform.position, hit.point);
  1608.             float startingDistance = distance;
  1609.  
  1610.             while (distance > 0)
  1611.             {
  1612.                 Trail.transform.position = Vector3.Lerp(startPosition, hit.point, 1 - (distance / startingDistance));
  1613.                 distance -= Time.deltaTime * bulletSpeed;
  1614.  
  1615.                 yield return null;
  1616.             }
  1617.  
  1618.             Trail.transform.position = hit.point;
  1619.  
  1620.             if (hit.collider.GetComponentInParent<Health>() != null)
  1621.             {
  1622.                 if (hit.collider.GetComponentInParent<Health>().currentHealthState == Health.HealthState.Enemy)
  1623.                 {
  1624.  
  1625.                     bloodHitPool.GetPooledBloodHit(hit.point, Quaternion.LookRotation(hit.normal));
  1626.                 }
  1627.             }
  1628.             else if (hit.collider.CompareTag("Enemy") == false)
  1629.             {
  1630.                 missHitPool.GetPooledMissHit(hit.point, Quaternion.LookRotation(hit.normal));
  1631.  
  1632.             }
  1633.             //Destroy(Trail.gameObject, Trail.time);
  1634.         }
  1635.         private void MoveObj(GameObject gameobj, float speed)
  1636.         {
  1637.             // Move the object forward along its z-axis at the specified speed
  1638.             gameobj.transform.Translate(Vector3.forward * speed * Time.deltaTime);
  1639.         }
  1640.  
  1641.         private void TriggerKickback()
  1642.         {
  1643.             if (fpsController != null)
  1644.             {
  1645.                 fpsController.ApplyKickback(kickbackStrength);
  1646.             }
  1647.         }
  1648.         [SerializeField] private float recoilAmount = 1f; // Amount of recoil
  1649.         [SerializeField] private float recoilSpeed = 0.1f; // Speed of recoil effect
  1650.  
  1651.         private Quaternion originalRotation; // To store the original rotation of the gun
  1652.         private IEnumerator RecoilShake()
  1653.         {
  1654.             float time = 0f;
  1655.  
  1656.             while (time < recoilSpeed)
  1657.             {
  1658.                 // Apply recoil
  1659.                 gunRoot.gameObject.transform.localRotation = Quaternion.Lerp(gunRoot.gameObject.transform.localRotation, originalRotation * Quaternion.Euler(-recoilAmount, 0, 0), time * recoilSpeed);
  1660.                 time += Time.deltaTime;
  1661.                 yield return null;
  1662.             }
  1663.  
  1664.             time = 0f;
  1665.             while (time < recoilSpeed)
  1666.             {
  1667.                 // Return to original position
  1668.                 gunRoot.gameObject.transform.localRotation = Quaternion.Lerp(gunRoot.gameObject.transform.localRotation, originalRotation, time * recoilSpeed);
  1669.                 time += Time.deltaTime;
  1670.                 yield return null;
  1671.             }
  1672.         }
  1673.     }
  1674.  
  1675. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement