using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyFly : MonoBehaviour {

	// Use this for initialization
	Rigidbody2D rb2d;

	public float speed = 5;
	public float speedX;
	public float speedY;
	void Start () 
	{
		speedX = Random.Range(0, 2)>0 ? speed * -1 : speed;
		speedY = Random.Range(0, 2)>0 ? speed * -1 : speed;
		float x = speedX * Random.Range(0.5f,1.0f);	
		float y = speedY * Random.Range(0.5f,1.0f);	
		speedX = x;
		speedY = y;
		rb2d = GetComponent<Rigidbody2D> ();
		rb2d.velocity = new Vector2 (x, y);	
	}

	void OnTriggerEnter2D(Collider2D col)
	{
		if (col.tag == "Row")
		{
			rb2d.velocity = new Vector2(rb2d.velocity.x, rb2d.velocity.y * -1);
			speedY *= -1;
		}
		else if (col.tag == "Collumn")
		{
			rb2d.velocity = new Vector2(rb2d.velocity.x * -1, rb2d.velocity.y);
			speedX *= -1;
		}
		
	}

	public void stopObject()
	{

		rb2d.velocity = new Vector2 (0, 0);
	}

	public void startObject()
	{
		rb2d.velocity = new Vector2 (speedX, speedY);
	}
}
