Advertisement
BluePaint

claw

Oct 22nd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Claw : MonoBehaviour {
  6.  
  7. // Access to the transform component on origin, where the character is firing from
  8. public Transform origin;
  9.  
  10. // How fast claw travels once fired
  11. public float speed = 4f;
  12.  
  13. // Access to the PlayerMovement script
  14. public PlayerMovement playerMovementScript;
  15.  
  16. // Where the claw is traveled to once fired
  17. public Vector2 target;
  18.  
  19. // the lighter target becomes the child of the heavier target, and is dragged over
  20. public GameObject childObject;
  21.  
  22. // Draws the rope between the claw and the gun
  23. public LineRenderer lineRenderer;
  24.  
  25. // Used to determine if the claw is making contact with a light enemy
  26. public bool isHittingLightEnemy;
  27.  
  28. // Used to determine if the claw is retracting towards the gun
  29. public bool isRetracting;
  30.  
  31.  
  32. void Awake ()
  33. {
  34. lineRenderer = GetComponent<LineRenderer>();
  35. }
  36.  
  37. // Update is called once per frame
  38. void Update ()
  39. {
  40. float step = speed * Time.deltaTime;
  41. transform.position = Vector2.MoveTowards(transform.position, target, step);
  42. lineRenderer.SetPosition(0, origin.position);
  43. lineRenderer.SetPosition(1, transform.position);
  44. if (transform.position == origin.position && isRetracting)
  45. {
  46. playerMovementScript.PulledEnemy();
  47. gameObject.SetActive(false);
  48. }
  49. }
  50.  
  51. // Called from gun to set position of claw
  52. public void ClawTarget(Vector2 pos)
  53. {
  54. target = pos;
  55. }
  56.  
  57. void OnTriggerEnter2D(Collider2D other)
  58. {
  59. isRetracting = true;
  60. target = origin.position;
  61.  
  62. if (other.gameObject.CompareTag("Light Enemy"))
  63. {
  64. isHittingLightEnemy = true;
  65. childObject = other.gameObject;
  66. other.transform.SetParent(transform);
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement