Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ENEMIES SCRIPTS:
- StealthKillTrigger:
- using UnityEngine;
- public class StealthKillTrigger : MonoBehaviour
- {
- public enum KillType { Choke, Stab }
- public KillType killType = KillType.Stab;
- public string playerTag = "Player";
- public GameObject enemy;
- public float lowThreshold = 2f;
- public float highThreshold = 5f;
- private bool playerInRange = false;
- private GameObject player;
- private float holdTime = 0f;
- private bool isHolding = false;
- private void Update()
- {
- if (playerInRange)
- {
- if (Input.GetMouseButtonDown(0))
- {
- isHolding = true;
- holdTime = 0f;
- Debug.Log("Hold started");
- }
- if (Input.GetMouseButton(0) && isHolding)
- {
- holdTime += Time.deltaTime;
- }
- if (Input.GetMouseButtonUp(0) && isHolding)
- {
- Debug.Log($"Hold released after {holdTime} seconds");
- PlayStealthKill(player, holdTime);
- isHolding = false;
- holdTime = 0f;
- }
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag(playerTag))
- {
- playerInRange = true;
- player = other.gameObject;
- Debug.Log("Player entered kill trigger");
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.CompareTag(playerTag))
- {
- playerInRange = false;
- player = null;
- Debug.Log("Player exited kill trigger");
- isHolding = false;
- holdTime = 0f;
- }
- }
- private void PlayStealthKill(GameObject playerObj, float holdDuration)
- {
- if (playerObj == null) return;
- Animator playerAnim = playerObj.GetComponent<Animator>();
- if (playerAnim == null)
- {
- Debug.LogWarning("Player has no Animator component");
- return;
- }
- string playerTrigger = "";
- string enemyTrigger = "";
- if (killType == KillType.Choke)
- {
- playerTrigger = "ChokeKill";
- enemyTrigger = "ChokeDie";
- }
- else if (killType == KillType.Stab)
- {
- if (holdDuration < lowThreshold)
- {
- playerTrigger = "StabKill1";
- enemyTrigger = "StabDie1";
- }
- else if (holdDuration < highThreshold)
- {
- playerTrigger = "StabKill2";
- enemyTrigger = "StabDie2";
- }
- else
- {
- playerTrigger = "StabKill3";
- enemyTrigger = "StabDie3";
- }
- }
- playerAnim.SetTrigger(playerTrigger);
- Debug.Log("Playing player animation: " + playerTrigger);
- if (enemy != null)
- {
- Animator enemyAnim = enemy.GetComponent<Animator>();
- EnemyHealth_Stealth health = enemy.GetComponent<EnemyHealth_Stealth>();
- if (enemyAnim != null)
- {
- enemyAnim.SetTrigger(enemyTrigger);
- Debug.Log("Playing enemy animation: " + enemyTrigger);
- }
- else
- {
- Debug.LogWarning("Enemy has no Animator component");
- }
- if (health != null)
- {
- Debug.Log("Calling Die() on EnemyHealth_Stealth");
- health.Die();
- }
- else
- {
- Debug.LogWarning("Enemy does not have EnemyHealth_Stealth component");
- }
- }
- else
- {
- Debug.LogWarning("Enemy object is not assigned in StealthKillTrigger");
- }
- }
- }
- enemyhealth script:
- using UnityEngine;
- public class EnemyHealth_Stealth : MonoBehaviour
- {
- private bool isDead = false;
- private Animator anim;
- private Collider[] colliders;
- private Rigidbody[] rigidbodies;
- public float destroyDelay = 5f;
- void Awake()
- {
- anim = GetComponent<Animator>();
- if (anim == null)
- Debug.LogWarning("EnemyHealth_Stealth: Animator component not found!");
- colliders = GetComponentsInChildren<Collider>();
- rigidbodies = GetComponentsInChildren<Rigidbody>();
- foreach (Rigidbody rb in rigidbodies)
- {
- rb.isKinematic = true;
- }
- }
- public void Die()
- {
- if (isDead)
- {
- Debug.Log("EnemyHealth_Stealth: Die() called but already dead.");
- return;
- }
- isDead = true;
- Debug.Log("EnemyHealth_Stealth: Die() called, enemy is dying...");
- // Disable all scripts except this one
- MonoBehaviour[] allScripts = GetComponents<MonoBehaviour>();
- foreach (var script in allScripts)
- {
- if (script != this)
- script.enabled = false;
- }
- // ❌ Animation trigger REMOVED to avoid conflict with StealthKillTrigger
- // Disable colliders
- foreach (Collider col in colliders)
- {
- col.enabled = false;
- }
- // Destroy after delay
- Destroy(gameObject, destroyDelay);
- }
- }
- PLAYER SCRIPTS:
- using UnityEngine;
- using System.Collections;
- public class PlayerKill : MonoBehaviour
- {
- public Animator anim;
- public Transform killPoint;
- public Transform knifeHoldPoint;
- private Enemy currentEnemy;
- private bool isKilling = false;
- public GameObject knife;
- private bool hasKnife = false;
- private Vector3 startKillPos;
- private Vector3 targetKillPos;
- private float killDuration = 2.5f;
- private float hangTime = 4.0f;
- private float killTimer = 0f;
- private bool isDescending = false;
- private bool isFrozen = false;
- private float slideSpeed = 0.13f;
- private float slideTimer = 0f;
- private float slideDuration = 2f;
- private bool isSecondSliding = false;
- private float secondSlideTimer = 0f;
- private float secondSlideDuration = 0.4f;
- private float secondSlideSpeed = 1.4f;
- void Update()
- {
- if (currentEnemy != null && Input.GetMouseButtonDown(0) && !isKilling)
- {
- isKilling = true;
- isFrozen = true;
- slideTimer = 0f;
- Vector3 startPosition = new Vector3(5.262238f, -1.000002f, 22.55484f);
- transform.position = startPosition;
- transform.rotation = Quaternion.Euler(0f, 67.041f, 0f);
- transform.position += new Vector3(0, 0.3f, 0);
- startKillPos = transform.position;
- targetKillPos = startKillPos - new Vector3(0, 0.3f, 0);
- currentEnemy.Die();
- StartCoroutine(WaitThenStartDescent());
- if (!hasKnife)
- {
- anim.SetTrigger("StealthKill"); // Pirmas killas be peilio
- StartCoroutine(WaitForAnimationAndPickupKnife());
- }
- else
- {
- // 3 stab'ai paeiliui jei jau turi peilį
- StartCoroutine(PlayMultipleStabAnimations(3));
- }
- }
- if (isFrozen && !isSecondSliding)
- {
- if (slideTimer < slideDuration)
- {
- transform.position += transform.forward * slideSpeed * Time.deltaTime;
- slideTimer += Time.deltaTime;
- if (slideTimer >= slideDuration)
- {
- StartCoroutine(StartSecondSlideAfterDelay(0.1f));
- }
- }
- }
- if (isSecondSliding)
- {
- if (secondSlideTimer < secondSlideDuration)
- {
- transform.position += transform.forward * secondSlideSpeed * Time.deltaTime;
- secondSlideTimer += Time.deltaTime;
- }
- else
- {
- isSecondSliding = false;
- isFrozen = false;
- }
- }
- if (isDescending)
- {
- killTimer += Time.deltaTime;
- float t = Mathf.Clamp01(killTimer / killDuration);
- transform.position = Vector3.Lerp(startKillPos, targetKillPos, t);
- if (t >= 1f)
- {
- StartCoroutine(ReturnToOriginalYAfter(4f));
- isKilling = false;
- isDescending = false;
- isFrozen = false;
- }
- }
- }
- IEnumerator WaitThenStartDescent()
- {
- yield return new WaitForSeconds(hangTime);
- killTimer = 0f;
- isDescending = true;
- }
- IEnumerator StartSecondSlideAfterDelay(float delay)
- {
- yield return new WaitForSeconds(delay);
- secondSlideTimer = 0f;
- isSecondSliding = true;
- }
- IEnumerator ReturnToOriginalYAfter(float delay)
- {
- yield return new WaitForSeconds(delay);
- transform.position = new Vector3(transform.position.x, startKillPos.y - 0.3f, transform.position.z);
- }
- IEnumerator WaitForAnimationAndPickupKnife()
- {
- yield return new WaitForSeconds(anim.GetCurrentAnimatorStateInfo(0).length);
- PickupKnife();
- }
- IEnumerator PlayMultipleStabAnimations(int stabCount)
- {
- for (int i = 0; i < stabCount; i++)
- {
- anim.SetTrigger("StabKill");
- // Palaukiam kol animator pereis į "StabKill" state
- yield return new WaitUntil(() => anim.GetCurrentAnimatorStateInfo(0).IsName("StabKill"));
- // Palaukiam kol animacija pasibaigs (normalizedTime >= 1)
- yield return new WaitUntil(() => anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f);
- // Nedidelis delay tarp stabų
- yield return new WaitForSeconds(0.05f);
- }
- PickupKnife();
- }
- void PickupKnife()
- {
- if (!hasKnife && currentEnemy != null)
- {
- GameObject enemyKnife = currentEnemy.GetKnife();
- if (enemyKnife != null && knifeHoldPoint != null)
- {
- enemyKnife.transform.SetParent(knifeHoldPoint);
- enemyKnife.transform.localPosition = Vector3.zero;
- enemyKnife.transform.localRotation = Quaternion.identity;
- knife = enemyKnife;
- hasKnife = true;
- Debug.Log("Peilis paimtas iš priešo ir pridėtas į ranką!");
- }
- }
- }
- void OnTriggerEnter(Collider other)
- {
- Enemy enemy = other.GetComponent<Enemy>();
- if (enemy != null)
- {
- currentEnemy = enemy;
- }
- }
- void OnTriggerExit(Collider other)
- {
- Enemy enemy = other.GetComponent<Enemy>();
- if (enemy != null && currentEnemy == enemy)
- {
- currentEnemy = null;
- }
- }
- // --- PRIDEDAMAS NAUJAS VIEŠAS METODAS ---
- public void GiveKnife()
- {
- if (!hasKnife && knifeHoldPoint != null)
- {
- if (knife != null)
- {
- knife.transform.SetParent(knifeHoldPoint);
- knife.transform.localPosition = Vector3.zero;
- knife.transform.localRotation = Quaternion.identity;
- hasKnife = true;
- Debug.Log("Peilis žaidėjui pridėtas per GiveKnife()!");
- }
- else
- {
- Debug.LogWarning("GiveKnife() nepavyko: peilio GameObject nenustatytas!");
- }
- }
- else
- {
- Debug.LogWarning("GiveKnife() nepavyko: jau turi peilį arba knifeHoldPoint nenustatytas!");
- }
- }
- }
- Adrenalineeffectcontroller (might be irrelavant):
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Rendering;
- public class AdrenalineEffectController : MonoBehaviour
- {
- public enum AdrenalineLevel { Low, Medium, High }
- public float holdTime = 0f;
- public bool isHolding = false;
- [Header("Screen Effects")]
- public Volume postProcessingVolume;
- public Image screenOverlay;
- public Color whiteColor = new Color(1, 1, 1, 0.2f);
- public Color yellowColor = new Color(1, 1, 0, 0.2f);
- public Color redColor = new Color(1, 0, 0, 0.3f);
- public float overlayFadeSpeed = 2f;
- private Color targetColor;
- private Vector3 originalCamPos;
- private Camera mainCam;
- void Start()
- {
- if (screenOverlay != null)
- screenOverlay.color = Color.clear;
- mainCam = Camera.main;
- if (mainCam != null)
- originalCamPos = mainCam.transform.localPosition;
- }
- void Update()
- {
- if (Input.GetMouseButton(0))
- {
- isHolding = true;
- holdTime += Time.deltaTime;
- UpdateAdrenalineVisuals();
- }
- if (Input.GetMouseButtonUp(0))
- {
- isHolding = false;
- holdTime = 0f;
- ResetEffects();
- }
- if (screenOverlay != null)
- {
- screenOverlay.color = Color.Lerp(screenOverlay.color, targetColor, Time.deltaTime * overlayFadeSpeed);
- }
- }
- public AdrenalineLevel GetAdrenalineLevel()
- {
- if (holdTime >= 6f)
- return AdrenalineLevel.High;
- else if (holdTime >= 2f)
- return AdrenalineLevel.Medium;
- else
- return AdrenalineLevel.Low;
- }
- void UpdateAdrenalineVisuals()
- {
- AdrenalineLevel level = GetAdrenalineLevel();
- switch (level)
- {
- case AdrenalineLevel.Low:
- targetColor = whiteColor;
- break;
- case AdrenalineLevel.Medium:
- targetColor = yellowColor;
- break;
- case AdrenalineLevel.High:
- targetColor = redColor;
- ShakeCamera();
- break;
- }
- }
- void ResetEffects()
- {
- targetColor = Color.clear;
- if (mainCam != null)
- mainCam.transform.localPosition = originalCamPos;
- }
- void ShakeCamera()
- {
- if (mainCam == null) return;
- float intensity = 0.05f;
- float shakeSpeed = 20f;
- Vector3 shakeOffset = new Vector3(
- Mathf.Sin(Time.time * shakeSpeed),
- Mathf.Cos(Time.time * shakeSpeed),
- 0f
- ) * intensity;
- mainCam.transform.localPosition = originalCamPos + shakeOffset;
- }
- public void SetAdrenalineLevel(AdrenalineLevel level)
- {
- switch (level)
- {
- case AdrenalineLevel.Low:
- targetColor = whiteColor;
- break;
- case AdrenalineLevel.Medium:
- targetColor = yellowColor;
- break;
- case AdrenalineLevel.High:
- targetColor = redColor;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment