Eonirr

Untitled

Mar 2nd, 2026
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3.  
  4. public class GrappleThrow : MonoBehaviour
  5. {
  6. public float grappleThrowSpeed;
  7. public float extendSpeed;
  8. public float retractSpeed;
  9.  
  10. [Space()]
  11. public Rigidbody2D grappleEndRb;
  12.  
  13. public List<DistanceJoint2D> jointList = new();
  14.  
  15. public bool extending;
  16. public bool retracting;
  17.  
  18. void Update()
  19. {
  20. if(extending)
  21. {
  22. grappleEndRb.AddForce(transform.right * grappleThrowSpeed, ForceMode2D.Impulse);
  23. foreach (var joint in jointList)
  24. {
  25. joint.distance += extendSpeed * Time.deltaTime;
  26. }
  27. }
  28. else if(retracting)
  29. {
  30. foreach (var joint in jointList)
  31. {
  32. joint.distance -= retractSpeed * Time.deltaTime;
  33. }
  34. }
  35. }
  36.  
  37. [ContextMenu("Extend")]
  38. public void Extend()
  39. {
  40. extending = true;
  41. retracting = false;
  42. }
  43.  
  44. [ContextMenu("Retract")]
  45. public void Retract()
  46. {
  47. extending = false;
  48. retracting = true;
  49. }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment