Advertisement
283375

KnifeItem attack cooldown (v50)

Apr 16th, 2024
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | Source Code | 0 0
  1. /**
  2.  * Although the KnifeItem.prefab says `useCooldown: 0`, the `KnifeItem.HitKnife` has a special logic:
  3.  * (Unrelated parts omitted)
  4.  */
  5. public class KnifeItem : GrabbableObject
  6. {
  7.     public int knifeHitForce = 1;
  8.  
  9.     public override void ItemActivate(bool used, bool buttonDown = true)
  10.     {
  11.         if (base.IsOwner) { HitKnife(); }
  12.     }
  13.  
  14.     public void HitKnife(bool cancel = false)
  15.     {
  16.         if (!cancel)
  17.         {
  18.             objectsHitByKnife = Physics.SphereCastAll( /* ... */ );
  19.             objectsHitByKnifeList = objectsHitByKnife /* ... */ ;
  20.             for (int i = 0; i < objectsHitByKnifeList.Count; i++)
  21.             {
  22.                 if (/* hit on special layers */) { /* ... */ }
  23.                 else
  24.                 {
  25.                     if ( /* hit on walls, floors, etc., */ ) continue;
  26.                     try
  27.                     {
  28.                         if (Time.realtimeSinceStartup - timeAtLastDamageDealt > 0.43f)  // <-- [!]
  29.                         {
  30.                             timeAtLastDamageDealt = Time.realtimeSinceStartup;
  31.                             component.Hit(knifeHitForce, forward, previousPlayerHeldBy, playHitSFX: true, 5);
  32.                             bloodParticle.Play(withChildren: true);
  33.                         }
  34.                     }
  35.                     catch (Exception arg) Debug.Log("...");
  36.                 }
  37.             }
  38.         }
  39.     }
  40.  
  41.     // other methods ...
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement