Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Animancer;
- using CodeStage.AntiCheat.ObscuredTypes;
- using CodeStage.AntiCheat.Storage;
- using DarkTreeFPS;
- using SecureVariables;
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- using Unity.VisualScripting;
- using UnityEngine;
- using UnityEngine.UIElements;
- namespace TMG_Gun
- {
- public class Gun : MonoBehaviour
- {
- public SecureFloat maxDamageToDo = 10f;
- public SecureFloat minDamageToDo = 5f;
- public SecureFloat bulletSpeed = 25f;
- public SecureInt bulletVisual = 0;
- [SerializeField]private SecureBool canADS = true;
- [SerializeField] private SecureBool damageFromCamera = false;
- [SerializeField] private Vector3 adsOffset = Vector3.zero;
- [Header("lower is higher zoom!")]
- [SerializeField] private float adsZoom = 40;
- [SerializeField] private SecureBool useBulletTrail = true;
- [SerializeField] private AnimationClip reloadClip;
- [SerializeField] private AnimancerComponent animancerComponent;
- [SerializeField] private SecureString gunName = "rifle";
- [SerializeField] private SecureBool isAuto = false;
- public GameObject projectile;
- [SerializeField] private SecureBool useProjectile = true;
- [SerializeField] private SecureBool visualFromGun = true;
- [Header("Don't exceed 10k projectile speed unless physics are higher")]
- [Range(200,10000)]public float rangeProjectileSpeed = 100;
- [SerializeField] private SecureBool useReplaceRay = false;
- [SerializeField] private SecureFloat replaceWithRayDistance = 5f;
- [Header("settings for both modes")]
- [SerializeField] private SecureFloat reloadingTimeMultiplier = 1f; // Strength of the kickback
- [SerializeField] private SecureFloat kickbackStrength = 5f; // Strength of the kickback
- [SerializeField] private SecureFloat fireRate = 0.5f;
- [SerializeField] private SecureFloat sprayAmount = 0.5f; // Control the amount of spray
- [SerializeField] private SecureInt ammoCount = 30; // Control the amount of spray
- [SerializeField] private SecureInt accurateBulletOverrideCount = 2;
- [SerializeField] private SecureFloat accurateBulletResetTime = 1f;
- [SerializeField] private SecureFloat range = 100f;
- private SecureBool canFire = true;
- private GameObject ammoPoolObj;
- private ObjectPool objectPool;
- private AudioSource audioSource;
- [Header("Audio")]
- [SerializeField] private SecureFloat volume = 0.1f; // Control the amount of spray
- public AudioClip shootclip;
- private FPS_Controller fpsController;
- private AimDownSights aimDownSights;
- private BulletTrailPooling bulletTrailPool;
- private MuzzleFlashPooling muzzleFlashPooling;
- private SecureInt shotsFired = 0;
- private float accurateTimer = 0;
- private SecureBool isShooting = false;
- public LayerMask mask;
- private MissHitPooling missHitPool;
- private BloodHitPooling bloodHitPool;
- private BloodDecalPooling bloodDecalPool;
- private SecureFloat footPenalty = 2f;
- private SecureFloat handPenalty = 2f;
- private SecureFloat armPenalty = 1.5f;
- private SecureFloat legPenalty = 1.5f;
- private SecureFloat headShotBuff = 2f;
- private bool toggle = false;
- private AimGunAtRaycast aimGunAtRaycast;
- private SecureBool enemyHit;
- private bool bulletShot = false;
- public static bool aimingDownSights;
- public GameObject nextRayCheckObj;
- private GunRoot gunRoot;
- private void OnDrawGizmos()
- {
- // Draw the ray in the editor for debugging purposes
- Gizmos.color = Color.blue;
- Gizmos.DrawLine(transform.position, transform.position + transform.forward * range);
- }
- private void OnEnable()
- {
- aimingDownSights = false;
- toggle = false;
- canFire = true;
- //spawn new pool
- ammoPoolObj = new GameObject();
- objectPool = ammoPoolObj.AddComponent<ObjectPool>();
- objectPool.prefab = projectile;
- objectPool.poolSize = ammoCount;
- objectPool.gameObject.name = "PlayerAmmoPool";
- //objectPool = GameObject.FindGameObjectWithTag("PlayerAmmoPool").GetComponent<ObjectPool>();
- if(useProjectile)
- {
- GameManager.usingProjectileGun = true;
- }
- else
- {
- GameManager.usingProjectileGun = false;
- }
- }
- private void OnDisable()
- {
- //remove pool
- Destroy(ammoPoolObj);
- }
- private void Start()
- {
- gunRoot = GetComponentInParent<GunRoot>();
- originalRotation = gunRoot.transform.localRotation;
- otherMask = LayerMask.GetMask("Default");
- ObscuredPrefs.Set<int>(gunName + "_Ammo", ammoCount);
- projectile.GetComponent<Projectile>().maxDamageToDo = maxDamageToDo;
- projectile.GetComponent<Projectile>().minDamageToDo = minDamageToDo;
- fpsController = FindObjectOfType<FPS_Controller>();
- aimDownSights = FindObjectOfType<AimDownSights>();
- bulletTrailPool = FindObjectOfType<BulletTrailPooling>();
- muzzleFlashPooling = FindObjectOfType<MuzzleFlashPooling>();
- audioSource = GetComponentInParent<AudioSource>();
- missHitPool = FindObjectOfType<MissHitPooling>();
- bloodHitPool = FindObjectOfType<BloodHitPooling>();
- bloodDecalPool = FindObjectOfType<BloodDecalPooling>();
- aimGunAtRaycast = GetComponentInParent<AimGunAtRaycast>();
- }
- void Update()
- {
- GameManager.currentAmmo = ObscuredPrefs.Get<int>(gunName + "_Ammo");
- GameManager.currentMaxAmmo = ammoCount;
- //Debug.Log(ObscuredPrefs.Get<int>(gunName + "_Ammo"));
- if (GameManager.blockShootingInput == false)
- {
- if (GameManager.currentAmmo > 0 && GameManager.reloading == false)
- {
- if (isAuto)
- {
- if (canFire && KeyBindingManager.GetKey(KeyAction.shoot))
- {
- StartCoroutine(FireCooldown());
- RangeAttack();
- }
- }
- else
- {
- if (KeyBindingManager.GetKeyDown(KeyAction.shoot))
- {
- RangeAttack();
- }
- }
- }
- //check if shooting
- if (KeyBindingManager.GetKey(KeyAction.shoot))
- {
- isShooting = true;
- }
- else
- {
- isShooting = false;
- }
- }
- //reload
- if (KeyBindingManager.GetKeyDown(KeyAction.reload) && ObscuredPrefs.Get<int>(gunName + "_Ammo") < ammoCount)
- {
- StartCoroutine(ReloadGun());
- GameManager.reloading = true;
- }
- //Debug.Log(isShooting);
- //accuracy override
- if (shotsFired > 0)
- {
- //Debug.Log("accuracy timer started");
- accurateTimer += Time.deltaTime;
- if (isShooting == false)
- {
- if (accurateTimer > accurateBulletResetTime)
- {
- //Debug.Log("accuracy timer finished");
- shotsFired = 0;
- accurateTimer = 0;
- }
- }
- else
- {
- accurateTimer = 0;
- }
- }
- if(canADS)
- {
- if (KeyBindingManager.GetKey(KeyAction.aim) && GameManager.reloading == false)
- {
- aimDownSights.mainCamera.fieldOfView = adsZoom;
- aimDownSights.gunCamera.fieldOfView = adsZoom;
- aimDownSights.gunRoot.transform.position = aimDownSights.adsPos.transform.position + adsOffset;
- aimGunAtRaycast.enabled = false;
- aimDownSights.gunRoot.transform.rotation = Quaternion.LookRotation(aimDownSights.adsPos.transform.forward);
- aimingDownSights = true;
- toggle = false;
- }
- else
- {
- DisableAds();
- }
- }
- else
- {
- DisableAds();
- }
- }
- private void DisableAds()
- {
- if (toggle == false)
- {
- aimDownSights.mainCamera.fieldOfView = 60;
- aimDownSights.gunCamera.fieldOfView = 60;
- aimDownSights.gunRoot.transform.position = aimDownSights.gunPos.transform.position;
- aimGunAtRaycast.enabled = true;
- aimingDownSights = false;
- toggle = true;
- }
- }
- IEnumerator ReloadGun()
- {
- shotsFired = 0;
- float reloadtime = 1 * reloadingTimeMultiplier;
- float reloadspeed = 1 / reloadingTimeMultiplier;
- var state = animancerComponent.Play(reloadClip);
- state.Speed = reloadspeed;
- // Assuming aimDownSights.gunRoot is your gun's transform
- aimDownSights.gunRoot.transform.position = aimDownSights.reloadPos.transform.position;
- // Create a -45-degree rotation Quaternion around the Y axis for local rotation
- Quaternion localRotation45DegreesY = Quaternion.Euler(0, -45, 0);
- // Apply the local rotation
- aimDownSights.gunRoot.transform.localRotation = localRotation45DegreesY;
- yield return new WaitForSeconds(reloadtime);
- animancerComponent.Stop(reloadClip);
- aimDownSights.gunRoot.transform.rotation = aimDownSights.originalAngle;
- aimDownSights.gunRoot.transform.position = aimDownSights.gunPos.transform.position;
- ObscuredPrefs.Set<int>(gunName + "_Ammo", ammoCount);
- GameManager.reloading = false;
- //aimDownSights.gunRoot = aimDownSights.gunPos;
- }
- IEnumerator FireCooldown()
- {
- canFire = false;
- yield return new WaitForSeconds(fireRate);
- canFire = true;
- }
- private void CastProjectileTrail()
- {
- if (visualFromGun)
- {
- trailObjectGun = bulletTrailPool.GetPooledBulletTrail(gameObject.transform.position, shootRotation);
- trailObjectGun.GetComponent<BulletModelSelection>().bulletToFire[bulletVisual].SetActive(true);
- trailObjectGun.GetComponent<Rigidbody>().AddForce(shootDirection * rangeProjectileSpeed, ForceMode.Force);
- }
- else
- {
- trailObjectCam = bulletTrailPool.GetPooledBulletTrail(Camera.main.transform.position, shootRotation);
- trailObjectCam.GetComponent<BulletModelSelection>().bulletToFire[bulletVisual].SetActive(true);
- trailObjectCam.GetComponent<Rigidbody>().AddForce(shootDirection * rangeProjectileSpeed, ForceMode.Force);
- }
- }
- private void CastBullet(GameObject bulletpos)
- {
- // Get an object from the pool and move it to a random position
- GameObject proj = objectPool.GetObject();
- proj.transform.position = bulletpos.transform.position;
- proj.transform.rotation = shootRotation;
- // Set the projectile's velocity
- proj.GetComponent<Rigidbody>().AddForce(shootDirection * rangeProjectileSpeed, ForceMode.Force);
- proj.GetComponent<BalisticProjectile>().initialVelocity = rangeProjectileSpeed;
- if (useBulletTrail)
- {
- CastProjectileTrail();
- }
- }
- private LayerMask otherMask;
- private Quaternion shootRotation;
- private Vector3 shootDirection;
- private Vector3 barrel;
- private GameObject trailObjectGun;
- private GameObject trailObjectCam;
- public void RangeAttack()
- {
- StartCoroutine(RecoilShake());
- if (damageFromCamera)
- {
- barrel = Camera.main.transform.position;
- }
- else
- {
- barrel = nextRayCheckObj.transform.position;
- }
- origin = barrel; // Start position of the ray
- direction = transform.forward; // Direction of the ray
- distanceTraveled = 0f;
- // Get shoot direction with conditional spray based on shot count and auto mode
- Vector3 sprayOffset = Vector3.zero;
- if (shotsFired > accurateBulletOverrideCount)
- {
- sprayOffset = Random.insideUnitSphere * sprayAmount;
- }
- if (damageFromCamera)
- {
- //get shoot dir
- shootDirection = Camera.main.transform.forward + sprayOffset;
- }
- else
- {
- //get shoot dir
- shootDirection = transform.forward + sprayOffset;
- }
- shootDirection.Normalize();
- // Calculate the Quaternion rotation for the shoot direction
- shootRotation = Quaternion.LookRotation(shootDirection);
- //play gunshot sound
- //audioManager.PlayEffectClipAtPoint(shootclip, transform.position, volume);
- audioSource.PlayOneShot(shootclip, volume);
- //muzzle flash
- muzzleFlashPooling.GetPooledMuzzleFlash(transform.position, transform.rotation);
- //spend ammo
- ObscuredPrefs.Set<int>(gunName + "_Ammo", ObscuredPrefs.Get<int>(gunName + "_Ammo") - 1);
- // Increment the number of shots fired
- shotsFired++;
- TriggerKickback();
- if (useProjectile)
- {
- if (damageFromCamera)
- {
- if (useReplaceRay == false)
- {
- CastBullet(Camera.main.gameObject);
- }
- else
- {
- // Define the ray. This will start at the game object's position and cast forward.
- Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
- // Prepare a variable to store the hit information.
- RaycastHit hit;
- // Cast the ray for a certain range and only against objects in the specified layerMask.
- if (Physics.Raycast(ray, out hit, replaceWithRayDistance, mask))
- {
- ApplyHit(hit);
- // Ray hit something, process the hit object.
- Debug.Log("Raycast hit: " + hit.collider.gameObject.name);
- if (useBulletTrail)
- {
- CastProjectileTrail();
- }
- }
- else if (useReplaceRay == false)
- {
- CastBullet(Camera.main.gameObject);
- }
- }
- }
- else
- {
- if (useReplaceRay == false)
- {
- CastBullet(gameObject);
- }
- else
- {
- // Define the ray. This will start at the game object's position and cast forward.
- Ray ray = new Ray(transform.position, transform.forward);
- // Prepare a variable to store the hit information.
- RaycastHit hit;
- // Cast the ray for a certain range and only against objects in the specified layerMask.
- if (Physics.Raycast(ray, out hit, replaceWithRayDistance, mask))
- {
- ApplyHit(hit);
- // Ray hit something, process the hit object.
- Debug.Log("Raycast hit: " + hit.collider.gameObject.name);
- if (useBulletTrail)
- {
- CastProjectileTrail();
- }
- }
- else
- {
- CastBullet(gameObject);
- }
- }
- }
- }
- else
- {
- bulletShot = true;
- StartCoroutine(ShootRayWithTravelTime());
- if (Physics.Raycast(barrel, shootDirection, out RaycastHit hit, range, mask))
- {
- if (hit.point != null)
- {
- if (useBulletTrail)
- {
- travelDistance = bulletSpeed * Time.deltaTime; // Calculate the distance the ray travels each frame
- GameObject trailObject = bulletTrailPool.GetPooledBulletTrail(transform.position, transform.rotation);
- trailObject.GetComponent<BulletModelSelection>().bulletToFire[bulletVisual].SetActive(true);
- trailObject.GetComponent<Rigidbody>().useGravity = false;
- //Destroy(trailObject.GetComponent<Rigidbody>());
- TrailRenderer trail = trailObject.GetComponent<TrailRenderer>(); // This line gets the TrailRenderer component
- StartCoroutine(SpawnTrail(trail, hit));
- }
- }
- }
- else
- {
- if (useBulletTrail)
- {
- GameObject trailObject = bulletTrailPool.GetPooledBulletTrail(transform.position, transform.rotation);
- TrailRenderer trail = trailObject.GetComponent<TrailRenderer>(); // This line gets the TrailRenderer component
- trailObject.GetComponent<BulletModelSelection>().bulletToFire[bulletVisual].SetActive(true);
- trailObject.GetComponent<Rigidbody>().useGravity = false;
- //Destroy(trailObject.GetComponent<Rigidbody>());
- Vector3 misseverything = transform.position + transform.forward * range;
- StartCoroutine(SpawnMissTrail(trail, misseverything));
- }
- }
- }
- }
- private float travelDistance;
- private RaycastHit hitInfo;
- private bool targetHit;
- private Vector3 direction;
- private Vector3 origin;
- private float distanceTraveled;
- IEnumerator ShootRayWithTravelTime()
- {
- while (bulletShot == true)
- {
- travelDistance = bulletSpeed * Time.deltaTime; // Calculate the distance the ray travels each frame
- RaycastHit hit;
- //Debug.Log("serious fuckery");
- // Check if the ray hits something
- if (Physics.Raycast(origin, direction, out hit, travelDistance, mask))
- {
- //Debug.Log("Hit: " + hit.collider.name); // Log the name of the hit object
- bulletShot = false;
- targetHit = true;
- hitInfo = hit; // Store the hit info for later
- if (hit.collider.GetComponentInParent<Health>() != null)
- {
- if (hit.collider.GetComponentInParent<Health>().currentHealthState == Health.HealthState.Enemy)
- {
- GameManager.enemyHit = true;
- //blood decal (wall)
- if (Physics.Raycast(barrel, shootDirection, out RaycastHit hit1, 15f, otherMask))
- {
- // Generate a random Z rotation angle
- float randomZRotation = Random.Range(0f, 360f);
- // Create a rotation that looks in the direction of the hit normal, then apply the random Z rotation
- Quaternion rotation = Quaternion.LookRotation(hit1.normal) * Quaternion.Euler(0, 0, randomZRotation);
- bloodDecalPool.GetPooledDecalBlood(hit1.point, rotation);
- }
- if (hit.collider.CompareTag("Enemy"))
- {
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(minDamageToDo, maxDamageToDo + 1));
- }
- if (hit.collider.CompareTag("EnemyHead"))
- {
- //Debug.Log("HEADSHOT");
- // Calculate and apply damage
- float min = minDamageToDo * headShotBuff;
- float max = maxDamageToDo * headShotBuff;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().headObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().headBox.SetActive(false);
- }
- }
- }
- if (hit.collider.CompareTag("EnemyRightHand"))
- {
- float min = minDamageToDo / handPenalty;
- float max = maxDamageToDo / handPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rHandObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rHandBox.SetActive(false);
- }
- }
- }
- if (hit.collider.CompareTag("EnemyRightUpperArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rUpperArmObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rUpperArmBox.SetActive(false);
- }
- }
- }
- }
- if (hit.collider.CompareTag("EnemyRightForeArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().rHandObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmBox.SetActive(false);
- }
- }
- }
- }
- if (hit.collider.CompareTag("EnemyLeftHand"))
- {
- float min = minDamageToDo / handPenalty;
- float max = maxDamageToDo / handPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lHandObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lHandBox.SetActive(false);
- }
- }
- }
- if (hit.collider.CompareTag("EnemyLeftForeArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().lHandObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmBox.SetActive(false);
- }
- }
- }
- }
- if (hit.collider.CompareTag("EnemyLeftUpperArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lUpperArmObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lUpperArmBox.SetActive(false);
- }
- }
- }
- }
- if (hit.collider.CompareTag("EnemyRightFoot"))
- {
- //Debug.Log("RIGHT FOOT HIT");
- float min = minDamageToDo / footPenalty;
- float max = maxDamageToDo / footPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().usingRightShoe)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rShoeObj.SetActive(false);
- }
- hit.collider.GetComponentInParent<DismembermenSettings>().rFootObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rFootBox.SetActive(false);
- }
- }
- }
- if (hit.collider.CompareTag("EnemyRightLowerLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().rFootObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegBox.SetActive(false);
- }
- }
- }
- }
- if (hit.collider.CompareTag("EnemyRightUpperLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rUpperLegObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rUpperLegBox.SetActive(false);
- }
- }
- }
- }
- if (hit.collider.CompareTag("EnemyLeftFoot"))
- {
- //Debug.Log("LEFT FOOT HIT");
- float min = minDamageToDo / footPenalty;
- float max = maxDamageToDo / footPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().usingRightShoe)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lShoeObj.SetActive(false);
- }
- hit.collider.GetComponentInParent<DismembermenSettings>().lFootObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lFootBox.SetActive(false);
- }
- }
- }
- if (hit.collider.CompareTag("EnemyLeftLowerLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().lFootObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegBox.SetActive(false);
- }
- }
- }
- }
- if (hit.collider.CompareTag("EnemyLeftUpperLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lUpperLegObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lUpperLegBox.SetActive(false);
- }
- }
- }
- }
- }
- }
- Debug.DrawLine(transform.position, hit.point, Color.yellow, 1f);
- }
- // Move the origin of the ray forward
- origin += direction * travelDistance;
- distanceTraveled += travelDistance;
- yield return null; // Wait until the next frame
- }
- // After the bullet has visually reached the target, apply damage
- if (targetHit)
- {
- //ApplyDamage(hitInfo);
- }
- }
- //HITSCAN
- public void ApplyHit(RaycastHit hit, GameObject bulletObj = null)
- {
- //Decrease health of object by calculatedDamage
- if (hit.collider.GetComponent<ObjectHealth>())
- hit.collider.GetComponent<ObjectHealth>().health -= Random.Range(minDamageToDo, maxDamageToDo + 1);
- if (hit.collider.GetComponentInParent<Health>())
- {
- if (hit.collider.GetComponentInParent<Health>().currentHealthState == Health.HealthState.Enemy)
- {
- //Debug.Log("hitting enemy second with ray");
- GameManager.enemyHit = true;
- enemyHit = true;
- if (hit.collider.CompareTag("Enemy"))
- {
- // Calculate and apply damage
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(minDamageToDo, maxDamageToDo + 1));
- // Handle blood hit effects
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- // Since we've hit an enemy, we don't need to check other colliders
- //break;
- }
- else if (hit.collider.CompareTag("EnemyHead"))
- {
- // Calculate and apply damage
- float min = minDamageToDo * headShotBuff;
- float max = maxDamageToDo * headShotBuff;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().headObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().headBox.SetActive(false);
- }
- }
- // Handle blood hit effects
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyRightHand"))
- {
- float min = minDamageToDo / handPenalty;
- float max = maxDamageToDo / handPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rHandObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rHandBox.SetActive(false);
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- //Destroy(gameObject);
- }
- else if (hit.collider.CompareTag("EnemyRightForeArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().rHandObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmBox.SetActive(false);
- }
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyRightUpperArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().rForeArmObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rUpperArmObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rUpperArmBox.SetActive(false);
- }
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyLeftHand"))
- {
- float min = minDamageToDo / handPenalty;
- float max = maxDamageToDo / handPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lHandObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lHandBox.SetActive(false);
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- //Destroy(gameObject);
- }
- else if (hit.collider.CompareTag("EnemyLeftForeArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().lHandObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmBox.SetActive(false);
- }
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyLeftUpperArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().lForeArmObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lUpperArmObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lUpperArmBox.SetActive(false);
- }
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyRightFoot"))
- {
- float min = minDamageToDo / footPenalty;
- float max = maxDamageToDo / footPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().usingRightShoe)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rShoeObj.SetActive(false);
- }
- hit.collider.GetComponentInParent<DismembermenSettings>().rFootObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rFootBox.SetActive(false);
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyRightLowerLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().rFootObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegBox.SetActive(false);
- }
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyRightUpperLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().rLowerLegObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().rUpperLegObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().rUpperLegBox.SetActive(false);
- }
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyLeftFoot"))
- {
- float min = minDamageToDo / footPenalty;
- float max = maxDamageToDo / footPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().usingRightShoe)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lShoeObj.SetActive(false);
- }
- hit.collider.GetComponentInParent<DismembermenSettings>().lFootObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lFootBox.SetActive(false);
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyLeftLowerLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().lFootObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegBox.SetActive(false);
- }
- }
- }
- DoBlood(hit);
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- else if (hit.collider.CompareTag("EnemyLeftUpperLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.collider.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.collider.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.collider.GetComponentInParent<DismembermenSettings>().lLowerLegObj.activeInHierarchy == false)
- {
- hit.collider.GetComponentInParent<DismembermenSettings>().lUpperLegObj.SetActive(false);
- hit.collider.GetComponentInParent<DismembermenSettings>().lUpperLegBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.collider.transform.position, Quaternion.LookRotation(hit.normal));
- if (bulletObj != null)
- {
- objectPool.ReturnObject(bulletObj);
- }
- }
- }
- }
- else
- {
- if (enemyHit == false)
- {
- missHitPool.GetPooledMissHit(hit.point, Quaternion.LookRotation(hit.normal));
- }
- else
- {
- enemyHit = false;
- }
- }
- /*
- if (hit.collider.CompareTag("Untagged"))
- {
- objectPool.ReturnObject(bulletObj);
- //StartCoroutine(ABC(bulletObj));
- }
- */
- }
- void DoBlood(RaycastHit hit)
- {
- bloodHitPool.GetPooledBloodHit(hit.collider.transform.position, Quaternion.LookRotation(hit.normal));
- }
- //PROJECITLE HIT
- public void TakeHit(Collider hit, GameObject bulletObj)
- {
- //Decrease health of object by calculatedDamage
- if (hit.GetComponent<ObjectHealth>())
- hit.GetComponent<ObjectHealth>().health -= Random.Range(minDamageToDo, maxDamageToDo + 1);
- if (hit.GetComponentInParent<Health>())
- {
- if (hit.GetComponentInParent<Health>().currentHealthState == Health.HealthState.Enemy)
- {
- GameManager.enemyHit = true;
- enemyHit = true;
- if (hit.CompareTag("Enemy"))
- {
- // Calculate and apply damage
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(minDamageToDo, maxDamageToDo + 1));
- // Handle blood hit effects
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- // Since we've hit an enemy, we don't need to check other colliders
- //break;
- }
- else if (hit.CompareTag("EnemyHead"))
- {
- // Calculate and apply damage
- float min = minDamageToDo * headShotBuff;
- float max = maxDamageToDo * headShotBuff;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.GetComponentInParent<DismembermenSettings>().headObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().headBox.SetActive(false);
- }
- }
- // Handle blood hit effects
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- //objectPool.ReturnObject(bulletObj);
- // Return the projectile to the object pool
- Debug.Log("headshot");
- // Since we've hit an enemy, we don't need to check other colliders
- //break;
- }
- else if (hit.CompareTag("EnemyRightHand"))
- {
- float min = minDamageToDo / handPenalty;
- float max = maxDamageToDo / handPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.GetComponentInParent<DismembermenSettings>().rHandObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().rHandBox.SetActive(false);
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- //Destroy(gameObject);
- }
- else if (hit.CompareTag("EnemyRightForeArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().rHandObj.activeInHierarchy == false)
- {
- hit.GetComponentInParent<DismembermenSettings>().rForeArmObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().rForeArmBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyRightUpperArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().rForeArmObj.activeInHierarchy == false)
- {
- hit.GetComponentInParent<DismembermenSettings>().rUpperArmObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().rUpperArmBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyLeftHand"))
- {
- float min = minDamageToDo / handPenalty;
- float max = maxDamageToDo / handPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- hit.GetComponentInParent<DismembermenSettings>().lHandObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().lHandBox.SetActive(false);
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- //Destroy(gameObject);
- }
- else if (hit.CompareTag("EnemyLeftForeArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().lHandObj.activeInHierarchy == false)
- {
- hit.GetComponentInParent<DismembermenSettings>().lForeArmObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().lForeArmBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyLeftUpperArm"))
- {
- float min = minDamageToDo / armPenalty;
- float max = maxDamageToDo / armPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().lForeArmObj.activeInHierarchy == false)
- {
- hit.GetComponentInParent<DismembermenSettings>().lUpperArmObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().lUpperArmBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyRightFoot"))
- {
- float min = minDamageToDo / footPenalty;
- float max = maxDamageToDo / footPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().usingRightShoe)
- {
- hit.GetComponentInParent<DismembermenSettings>().rShoeObj.SetActive(false);
- }
- hit.GetComponentInParent<DismembermenSettings>().rFootObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().rFootBox.SetActive(false);
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyRightLowerLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().rFootObj.activeInHierarchy == false)
- {
- hit.GetComponentInParent<DismembermenSettings>().rLowerLegObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().rLowerLegBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyRightUpperLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().rLowerLegObj.activeInHierarchy == false)
- {
- hit.GetComponentInParent<DismembermenSettings>().rUpperLegObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().rUpperLegBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyLeftFoot"))
- {
- float min = minDamageToDo / footPenalty;
- float max = maxDamageToDo / footPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().usingRightShoe)
- {
- hit.GetComponentInParent<DismembermenSettings>().lShoeObj.SetActive(false);
- }
- hit.GetComponentInParent<DismembermenSettings>().lFootObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().lFootBox.SetActive(false);
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyLeftLowerLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().lFootObj.activeInHierarchy == false)
- {
- hit.GetComponentInParent<DismembermenSettings>().lLowerLegObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().lLowerLegBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- else if (hit.CompareTag("EnemyLeftUpperLeg"))
- {
- float min = minDamageToDo / legPenalty;
- float max = maxDamageToDo / legPenalty;
- hit.GetComponentInParent<Health>().TakeDamage(Random.Range(min, max + 1));
- // Loop through each element in the bodyParts array
- if (hit.GetComponentInParent<DismembermenSettings>() != null)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().dismemberMode)
- {
- if (hit.GetComponentInParent<DismembermenSettings>().lLowerLegObj.activeInHierarchy == false)
- {
- hit.GetComponentInParent<DismembermenSettings>().lUpperLegObj.SetActive(false);
- hit.GetComponentInParent<DismembermenSettings>().lUpperLegBox.SetActive(false);
- }
- }
- }
- bloodHitPool.GetPooledBloodHit(hit.transform.position, Quaternion.identity);
- objectPool.ReturnObject(bulletObj);
- }
- }
- }
- /*
- else
- {
- if (enemyHit == false)
- {
- }
- else
- {
- enemyHit = false;
- }
- }
- if (hit.collider.CompareTag("Untagged"))
- {
- objectPool.ReturnObject(bulletObj);
- //StartCoroutine(ABC(bulletObj));
- }
- */
- }
- private IEnumerator SpawnMissTrail(TrailRenderer trail, Vector3 miss)
- {
- float time = 0;
- Vector3 startpos = trail.transform.position;
- while (time < 0.1f)
- {
- trail.transform.position = Vector3.Lerp(startpos, miss, time);
- time += Time.deltaTime / 0.5f;
- yield return null;
- }
- trail.transform.position = miss;
- }
- private IEnumerator SpawnTrail(TrailRenderer Trail, RaycastHit hit)
- {
- Vector3 startPosition = Trail.transform.position;
- Vector3 direction = (hit.point - Trail.transform.position).normalized;
- float distance = Vector3.Distance(Trail.transform.position, hit.point);
- float startingDistance = distance;
- while (distance > 0)
- {
- Trail.transform.position = Vector3.Lerp(startPosition, hit.point, 1 - (distance / startingDistance));
- distance -= Time.deltaTime * bulletSpeed;
- yield return null;
- }
- Trail.transform.position = hit.point;
- if (hit.collider.GetComponentInParent<Health>() != null)
- {
- if (hit.collider.GetComponentInParent<Health>().currentHealthState == Health.HealthState.Enemy)
- {
- bloodHitPool.GetPooledBloodHit(hit.point, Quaternion.LookRotation(hit.normal));
- }
- }
- else if (hit.collider.CompareTag("Enemy") == false)
- {
- missHitPool.GetPooledMissHit(hit.point, Quaternion.LookRotation(hit.normal));
- }
- //Destroy(Trail.gameObject, Trail.time);
- }
- private void MoveObj(GameObject gameobj, float speed)
- {
- // Move the object forward along its z-axis at the specified speed
- gameobj.transform.Translate(Vector3.forward * speed * Time.deltaTime);
- }
- private void TriggerKickback()
- {
- if (fpsController != null)
- {
- fpsController.ApplyKickback(kickbackStrength);
- }
- }
- [SerializeField] private float recoilAmount = 1f; // Amount of recoil
- [SerializeField] private float recoilSpeed = 0.1f; // Speed of recoil effect
- private Quaternion originalRotation; // To store the original rotation of the gun
- private IEnumerator RecoilShake()
- {
- float time = 0f;
- while (time < recoilSpeed)
- {
- // Apply recoil
- gunRoot.gameObject.transform.localRotation = Quaternion.Lerp(gunRoot.gameObject.transform.localRotation, originalRotation * Quaternion.Euler(-recoilAmount, 0, 0), time * recoilSpeed);
- time += Time.deltaTime;
- yield return null;
- }
- time = 0f;
- while (time < recoilSpeed)
- {
- // Return to original position
- gunRoot.gameObject.transform.localRotation = Quaternion.Lerp(gunRoot.gameObject.transform.localRotation, originalRotation, time * recoilSpeed);
- time += Time.deltaTime;
- yield return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement