Advertisement
Festelo

Untitled

Jan 5th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class ActionBlock : MonoBehaviour {
  4.  
  5.     public int value;
  6.     public Vector2 vector;
  7.     public GameObject Parent;
  8.     GameObject enteredObject;
  9.  
  10.     int count;
  11.     private void Update()
  12.     {
  13.         if (active)
  14.         {
  15.             if (count == value)
  16.             {
  17.                 vector = Vector2.Reflect(vector, vector);
  18.             }
  19.             Parent.transform.Translate(vector * Time.deltaTime);
  20.             if(enteredObject != null)
  21.                 enteredObject.transform.Translate(vector * Time.deltaTime);
  22.             count++;
  23.         }
  24.     }
  25.  
  26.     // Use this for initialization
  27.     void Start () {
  28.     }
  29.  
  30.     bool active = false;
  31.  
  32.     void OnTriggerEnter2D(Collider2D collider)
  33.     {
  34.         if (collider.CompareTag("Player"))
  35.         {
  36.             enteredObject = collider.gameObject;
  37.             if (!active)
  38.             {
  39.                 active = true;
  40.             }
  41.         }
  42.     }
  43.     void OnTriggerExit2D(Collider2D collider)
  44.     {
  45.         enteredObject = null;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement