Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Claw : MonoBehaviour {
- // Access to the transform component on origin, where the character is firing from
- public Transform origin;
- // How fast claw travels once fired
- public float speed = 4f;
- // Access to the PlayerMovement script
- public PlayerMovement playerMovementScript;
- // Where the claw is traveled to once fired
- public Vector2 target;
- // the lighter target becomes the child of the heavier target, and is dragged over
- public GameObject childObject;
- // Draws the rope between the claw and the gun
- public LineRenderer lineRenderer;
- // Used to determine if the claw is making contact with a light enemy
- public bool isHittingLightEnemy;
- // Used to determine if the claw is retracting towards the gun
- public bool isRetracting;
- void Awake ()
- {
- lineRenderer = GetComponent<LineRenderer>();
- }
- // Update is called once per frame
- void Update ()
- {
- float step = speed * Time.deltaTime;
- transform.position = Vector2.MoveTowards(transform.position, target, step);
- lineRenderer.SetPosition(0, origin.position);
- lineRenderer.SetPosition(1, transform.position);
- if (transform.position == origin.position && isRetracting)
- {
- playerMovementScript.PulledEnemy();
- gameObject.SetActive(false);
- }
- }
- // Called from gun to set position of claw
- public void ClawTarget(Vector2 pos)
- {
- target = pos;
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- isRetracting = true;
- target = origin.position;
- if (other.gameObject.CompareTag("Light Enemy"))
- {
- isHittingLightEnemy = true;
- childObject = other.gameObject;
- other.transform.SetParent(transform);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement