Catholicsss

Untitled

Jul 11th, 2025
41
0
6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.98 KB | Gaming | 0 0
  1. ENEMIES SCRIPTS:
  2. StealthKillTrigger:
  3. using UnityEngine;
  4.  
  5. public class StealthKillTrigger : MonoBehaviour
  6. {
  7. public enum KillType { Choke, Stab }
  8. public KillType killType = KillType.Stab;
  9.  
  10. public string playerTag = "Player";
  11. public GameObject enemy;
  12.  
  13. public float lowThreshold = 2f;
  14. public float highThreshold = 5f;
  15.  
  16. private bool playerInRange = false;
  17. private GameObject player;
  18.  
  19. private float holdTime = 0f;
  20. private bool isHolding = false;
  21.  
  22. private void Update()
  23. {
  24. if (playerInRange)
  25. {
  26. if (Input.GetMouseButtonDown(0))
  27. {
  28. isHolding = true;
  29. holdTime = 0f;
  30. Debug.Log("Hold started");
  31. }
  32.  
  33. if (Input.GetMouseButton(0) && isHolding)
  34. {
  35. holdTime += Time.deltaTime;
  36. }
  37.  
  38. if (Input.GetMouseButtonUp(0) && isHolding)
  39. {
  40. Debug.Log($"Hold released after {holdTime} seconds");
  41. PlayStealthKill(player, holdTime);
  42. isHolding = false;
  43. holdTime = 0f;
  44. }
  45. }
  46. }
  47.  
  48. private void OnTriggerEnter(Collider other)
  49. {
  50. if (other.CompareTag(playerTag))
  51. {
  52. playerInRange = true;
  53. player = other.gameObject;
  54. Debug.Log("Player entered kill trigger");
  55. }
  56. }
  57.  
  58. private void OnTriggerExit(Collider other)
  59. {
  60. if (other.CompareTag(playerTag))
  61. {
  62. playerInRange = false;
  63. player = null;
  64. Debug.Log("Player exited kill trigger");
  65. isHolding = false;
  66. holdTime = 0f;
  67. }
  68. }
  69.  
  70. private void PlayStealthKill(GameObject playerObj, float holdDuration)
  71. {
  72. if (playerObj == null) return;
  73.  
  74. Animator playerAnim = playerObj.GetComponent<Animator>();
  75. if (playerAnim == null)
  76. {
  77. Debug.LogWarning("Player has no Animator component");
  78. return;
  79. }
  80.  
  81. string playerTrigger = "";
  82. string enemyTrigger = "";
  83.  
  84. if (killType == KillType.Choke)
  85. {
  86. playerTrigger = "ChokeKill";
  87. enemyTrigger = "ChokeDie";
  88. }
  89. else if (killType == KillType.Stab)
  90. {
  91. if (holdDuration < lowThreshold)
  92. {
  93. playerTrigger = "StabKill1";
  94. enemyTrigger = "StabDie1";
  95. }
  96. else if (holdDuration < highThreshold)
  97. {
  98. playerTrigger = "StabKill2";
  99. enemyTrigger = "StabDie2";
  100. }
  101. else
  102. {
  103. playerTrigger = "StabKill3";
  104. enemyTrigger = "StabDie3";
  105. }
  106. }
  107.  
  108. playerAnim.SetTrigger(playerTrigger);
  109. Debug.Log("Playing player animation: " + playerTrigger);
  110.  
  111. if (enemy != null)
  112. {
  113. Animator enemyAnim = enemy.GetComponent<Animator>();
  114. EnemyHealth_Stealth health = enemy.GetComponent<EnemyHealth_Stealth>();
  115.  
  116. if (enemyAnim != null)
  117. {
  118. enemyAnim.SetTrigger(enemyTrigger);
  119. Debug.Log("Playing enemy animation: " + enemyTrigger);
  120. }
  121. else
  122. {
  123. Debug.LogWarning("Enemy has no Animator component");
  124. }
  125.  
  126. if (health != null)
  127. {
  128. Debug.Log("Calling Die() on EnemyHealth_Stealth");
  129. health.Die();
  130. }
  131. else
  132. {
  133. Debug.LogWarning("Enemy does not have EnemyHealth_Stealth component");
  134. }
  135. }
  136. else
  137. {
  138. Debug.LogWarning("Enemy object is not assigned in StealthKillTrigger");
  139. }
  140. }
  141. }
  142.  
  143. enemyhealth script:
  144.  
  145. using UnityEngine;
  146.  
  147. public class EnemyHealth_Stealth : MonoBehaviour
  148. {
  149. private bool isDead = false;
  150. private Animator anim;
  151. private Collider[] colliders;
  152. private Rigidbody[] rigidbodies;
  153.  
  154. public float destroyDelay = 5f;
  155.  
  156. void Awake()
  157. {
  158. anim = GetComponent<Animator>();
  159. if (anim == null)
  160. Debug.LogWarning("EnemyHealth_Stealth: Animator component not found!");
  161.  
  162. colliders = GetComponentsInChildren<Collider>();
  163. rigidbodies = GetComponentsInChildren<Rigidbody>();
  164.  
  165. foreach (Rigidbody rb in rigidbodies)
  166. {
  167. rb.isKinematic = true;
  168. }
  169. }
  170.  
  171. public void Die()
  172. {
  173. if (isDead)
  174. {
  175. Debug.Log("EnemyHealth_Stealth: Die() called but already dead.");
  176. return;
  177. }
  178.  
  179. isDead = true;
  180. Debug.Log("EnemyHealth_Stealth: Die() called, enemy is dying...");
  181.  
  182. // Disable all scripts except this one
  183. MonoBehaviour[] allScripts = GetComponents<MonoBehaviour>();
  184. foreach (var script in allScripts)
  185. {
  186. if (script != this)
  187. script.enabled = false;
  188. }
  189.  
  190. // ❌ Animation trigger REMOVED to avoid conflict with StealthKillTrigger
  191.  
  192. // Disable colliders
  193. foreach (Collider col in colliders)
  194. {
  195. col.enabled = false;
  196. }
  197.  
  198. // Destroy after delay
  199. Destroy(gameObject, destroyDelay);
  200. }
  201. }
  202.  
  203. PLAYER SCRIPTS:
  204.  
  205. using UnityEngine;
  206. using System.Collections;
  207.  
  208. public class PlayerKill : MonoBehaviour
  209. {
  210. public Animator anim;
  211. public Transform killPoint;
  212. public Transform knifeHoldPoint;
  213.  
  214. private Enemy currentEnemy;
  215. private bool isKilling = false;
  216.  
  217. public GameObject knife;
  218. private bool hasKnife = false;
  219.  
  220. private Vector3 startKillPos;
  221. private Vector3 targetKillPos;
  222. private float killDuration = 2.5f;
  223. private float hangTime = 4.0f;
  224. private float killTimer = 0f;
  225. private bool isDescending = false;
  226.  
  227. private bool isFrozen = false;
  228. private float slideSpeed = 0.13f;
  229. private float slideTimer = 0f;
  230. private float slideDuration = 2f;
  231.  
  232. private bool isSecondSliding = false;
  233. private float secondSlideTimer = 0f;
  234. private float secondSlideDuration = 0.4f;
  235. private float secondSlideSpeed = 1.4f;
  236.  
  237. void Update()
  238. {
  239. if (currentEnemy != null && Input.GetMouseButtonDown(0) && !isKilling)
  240. {
  241. isKilling = true;
  242. isFrozen = true;
  243. slideTimer = 0f;
  244.  
  245. Vector3 startPosition = new Vector3(5.262238f, -1.000002f, 22.55484f);
  246. transform.position = startPosition;
  247. transform.rotation = Quaternion.Euler(0f, 67.041f, 0f);
  248. transform.position += new Vector3(0, 0.3f, 0);
  249.  
  250. startKillPos = transform.position;
  251. targetKillPos = startKillPos - new Vector3(0, 0.3f, 0);
  252.  
  253. currentEnemy.Die();
  254.  
  255. StartCoroutine(WaitThenStartDescent());
  256.  
  257. if (!hasKnife)
  258. {
  259. anim.SetTrigger("StealthKill"); // Pirmas killas be peilio
  260. StartCoroutine(WaitForAnimationAndPickupKnife());
  261. }
  262. else
  263. {
  264. // 3 stab'ai paeiliui jei jau turi peilį
  265. StartCoroutine(PlayMultipleStabAnimations(3));
  266. }
  267. }
  268.  
  269. if (isFrozen && !isSecondSliding)
  270. {
  271. if (slideTimer < slideDuration)
  272. {
  273. transform.position += transform.forward * slideSpeed * Time.deltaTime;
  274. slideTimer += Time.deltaTime;
  275.  
  276. if (slideTimer >= slideDuration)
  277. {
  278. StartCoroutine(StartSecondSlideAfterDelay(0.1f));
  279. }
  280. }
  281. }
  282.  
  283. if (isSecondSliding)
  284. {
  285. if (secondSlideTimer < secondSlideDuration)
  286. {
  287. transform.position += transform.forward * secondSlideSpeed * Time.deltaTime;
  288. secondSlideTimer += Time.deltaTime;
  289. }
  290. else
  291. {
  292. isSecondSliding = false;
  293. isFrozen = false;
  294. }
  295. }
  296.  
  297. if (isDescending)
  298. {
  299. killTimer += Time.deltaTime;
  300. float t = Mathf.Clamp01(killTimer / killDuration);
  301. transform.position = Vector3.Lerp(startKillPos, targetKillPos, t);
  302.  
  303. if (t >= 1f)
  304. {
  305. StartCoroutine(ReturnToOriginalYAfter(4f));
  306. isKilling = false;
  307. isDescending = false;
  308. isFrozen = false;
  309. }
  310. }
  311. }
  312.  
  313. IEnumerator WaitThenStartDescent()
  314. {
  315. yield return new WaitForSeconds(hangTime);
  316. killTimer = 0f;
  317. isDescending = true;
  318. }
  319.  
  320. IEnumerator StartSecondSlideAfterDelay(float delay)
  321. {
  322. yield return new WaitForSeconds(delay);
  323. secondSlideTimer = 0f;
  324. isSecondSliding = true;
  325. }
  326.  
  327. IEnumerator ReturnToOriginalYAfter(float delay)
  328. {
  329. yield return new WaitForSeconds(delay);
  330. transform.position = new Vector3(transform.position.x, startKillPos.y - 0.3f, transform.position.z);
  331. }
  332.  
  333. IEnumerator WaitForAnimationAndPickupKnife()
  334. {
  335. yield return new WaitForSeconds(anim.GetCurrentAnimatorStateInfo(0).length);
  336. PickupKnife();
  337. }
  338.  
  339. IEnumerator PlayMultipleStabAnimations(int stabCount)
  340. {
  341. for (int i = 0; i < stabCount; i++)
  342. {
  343. anim.SetTrigger("StabKill");
  344.  
  345. // Palaukiam kol animator pereis į "StabKill" state
  346. yield return new WaitUntil(() => anim.GetCurrentAnimatorStateInfo(0).IsName("StabKill"));
  347. // Palaukiam kol animacija pasibaigs (normalizedTime >= 1)
  348. yield return new WaitUntil(() => anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f);
  349.  
  350. // Nedidelis delay tarp stabų
  351. yield return new WaitForSeconds(0.05f);
  352. }
  353.  
  354. PickupKnife();
  355. }
  356.  
  357. void PickupKnife()
  358. {
  359. if (!hasKnife && currentEnemy != null)
  360. {
  361. GameObject enemyKnife = currentEnemy.GetKnife();
  362.  
  363. if (enemyKnife != null && knifeHoldPoint != null)
  364. {
  365. enemyKnife.transform.SetParent(knifeHoldPoint);
  366. enemyKnife.transform.localPosition = Vector3.zero;
  367. enemyKnife.transform.localRotation = Quaternion.identity;
  368.  
  369. knife = enemyKnife;
  370. hasKnife = true;
  371.  
  372. Debug.Log("Peilis paimtas iš priešo ir pridėtas į ranką!");
  373. }
  374. }
  375. }
  376.  
  377. void OnTriggerEnter(Collider other)
  378. {
  379. Enemy enemy = other.GetComponent<Enemy>();
  380. if (enemy != null)
  381. {
  382. currentEnemy = enemy;
  383. }
  384. }
  385.  
  386. void OnTriggerExit(Collider other)
  387. {
  388. Enemy enemy = other.GetComponent<Enemy>();
  389. if (enemy != null && currentEnemy == enemy)
  390. {
  391. currentEnemy = null;
  392. }
  393. }
  394.  
  395. // --- PRIDEDAMAS NAUJAS VIEŠAS METODAS ---
  396. public void GiveKnife()
  397. {
  398. if (!hasKnife && knifeHoldPoint != null)
  399. {
  400. if (knife != null)
  401. {
  402. knife.transform.SetParent(knifeHoldPoint);
  403. knife.transform.localPosition = Vector3.zero;
  404. knife.transform.localRotation = Quaternion.identity;
  405. hasKnife = true;
  406. Debug.Log("Peilis žaidėjui pridėtas per GiveKnife()!");
  407. }
  408. else
  409. {
  410. Debug.LogWarning("GiveKnife() nepavyko: peilio GameObject nenustatytas!");
  411. }
  412. }
  413. else
  414. {
  415. Debug.LogWarning("GiveKnife() nepavyko: jau turi peilį arba knifeHoldPoint nenustatytas!");
  416. }
  417. }
  418. }
  419.  
  420. Adrenalineeffectcontroller (might be irrelavant):
  421.  
  422. using UnityEngine;
  423. using UnityEngine.UI;
  424. using UnityEngine.Rendering;
  425.  
  426. public class AdrenalineEffectController : MonoBehaviour
  427. {
  428. public enum AdrenalineLevel { Low, Medium, High }
  429.  
  430. public float holdTime = 0f;
  431. public bool isHolding = false;
  432.  
  433. [Header("Screen Effects")]
  434. public Volume postProcessingVolume;
  435. public Image screenOverlay;
  436. public Color whiteColor = new Color(1, 1, 1, 0.2f);
  437. public Color yellowColor = new Color(1, 1, 0, 0.2f);
  438. public Color redColor = new Color(1, 0, 0, 0.3f);
  439. public float overlayFadeSpeed = 2f;
  440.  
  441. private Color targetColor;
  442. private Vector3 originalCamPos;
  443. private Camera mainCam;
  444.  
  445. void Start()
  446. {
  447. if (screenOverlay != null)
  448. screenOverlay.color = Color.clear;
  449.  
  450. mainCam = Camera.main;
  451. if (mainCam != null)
  452. originalCamPos = mainCam.transform.localPosition;
  453. }
  454.  
  455. void Update()
  456. {
  457. if (Input.GetMouseButton(0))
  458. {
  459. isHolding = true;
  460. holdTime += Time.deltaTime;
  461. UpdateAdrenalineVisuals();
  462. }
  463.  
  464. if (Input.GetMouseButtonUp(0))
  465. {
  466. isHolding = false;
  467. holdTime = 0f;
  468. ResetEffects();
  469. }
  470.  
  471. if (screenOverlay != null)
  472. {
  473. screenOverlay.color = Color.Lerp(screenOverlay.color, targetColor, Time.deltaTime * overlayFadeSpeed);
  474. }
  475. }
  476.  
  477. public AdrenalineLevel GetAdrenalineLevel()
  478. {
  479. if (holdTime >= 6f)
  480. return AdrenalineLevel.High;
  481. else if (holdTime >= 2f)
  482. return AdrenalineLevel.Medium;
  483. else
  484. return AdrenalineLevel.Low;
  485. }
  486.  
  487. void UpdateAdrenalineVisuals()
  488. {
  489. AdrenalineLevel level = GetAdrenalineLevel();
  490.  
  491. switch (level)
  492. {
  493. case AdrenalineLevel.Low:
  494. targetColor = whiteColor;
  495. break;
  496. case AdrenalineLevel.Medium:
  497. targetColor = yellowColor;
  498. break;
  499. case AdrenalineLevel.High:
  500. targetColor = redColor;
  501. ShakeCamera();
  502. break;
  503. }
  504. }
  505.  
  506. void ResetEffects()
  507. {
  508. targetColor = Color.clear;
  509. if (mainCam != null)
  510. mainCam.transform.localPosition = originalCamPos;
  511. }
  512.  
  513. void ShakeCamera()
  514. {
  515. if (mainCam == null) return;
  516.  
  517. float intensity = 0.05f;
  518. float shakeSpeed = 20f;
  519.  
  520. Vector3 shakeOffset = new Vector3(
  521. Mathf.Sin(Time.time * shakeSpeed),
  522. Mathf.Cos(Time.time * shakeSpeed),
  523. 0f
  524. ) * intensity;
  525.  
  526. mainCam.transform.localPosition = originalCamPos + shakeOffset;
  527. }
  528.  
  529. public void SetAdrenalineLevel(AdrenalineLevel level)
  530. {
  531. switch (level)
  532. {
  533. case AdrenalineLevel.Low:
  534. targetColor = whiteColor;
  535. break;
  536. case AdrenalineLevel.Medium:
  537. targetColor = yellowColor;
  538. break;
  539. case AdrenalineLevel.High:
  540. targetColor = redColor;
  541. break;
  542. }
  543. }
  544. }
  545.  
  546.  
Advertisement
Add Comment
Please, Sign In to add comment