Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Snag : MonoBehaviour {
- public GameObject gPlayer;
- //public Player _Player;
- public ChainThings _ChainThings;
- public float direction = 0;
- public float burnout = 0;
- private LineRenderer twochain;
- void Start () {
- twochain = gameObject.GetComponent<LineRenderer>();
- twochain.enabled = true;
- gPlayer = GameObject.Find ("Player");
- //_Player.holdEnemy ();
- _ChainThings.holdEnemy ();
- }
- // Gets called once when the bullet is created
- void Update () {
- if (Input.GetKeyDown ("left")) {
- direction = 1;
- }
- if (Input.GetKeyDown ("right")) {
- direction = 2;
- }
- if (Input.GetKeyDown ("down")) {
- direction = 3;
- }
- if (Input.GetKeyDown ("up")) {
- direction = 4;
- }
- twochain.SetPosition (1, transform.position);
- twochain.SetPosition (0, gPlayer.transform.position);
- if (direction == 1) {
- Vector3 tempPos = transform.position;
- tempPos.x += 30 * Time.deltaTime;
- tempPos.y = gPlayer.transform.position.y;
- transform.position = tempPos;
- }
- if (direction == 2) {
- Vector3 tempPos = transform.position;
- tempPos.x -= 30 * Time.deltaTime;
- tempPos.y = gPlayer.transform.position.y;
- transform.position = tempPos;
- }
- if (direction == 4) {
- Vector3 tempPos = transform.position;
- tempPos.y += 30 * Time.deltaTime;
- tempPos.x = gPlayer.transform.position.x;
- transform.position = tempPos;
- }
- if (direction == 3) {
- Vector3 tempPos = transform.position;
- tempPos.y -= 30 * Time.deltaTime;
- tempPos.x = gPlayer.transform.position.x;
- transform.position = tempPos;
- }
- burnout += 1 * Time.deltaTime;
- if (burnout > 1) {
- Destroy (gameObject);
- }
- }
- void FixedUpdate () {
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- if (other.tag == "Enemy" || other.tag == "ground") {
- _ChainThings.holdEnemy();
- Destroy (gameObject);
- }
- }
- // Gets called when the object goes out of the screen
- void OnBecameInvisible() {
- // Destroy the bullet
- //Destroy(gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement