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

public class ControlDeBala : MonoBehaviour {

	private Rigidbody2D buletRb;
	//Tomamos el jugador
	private GameObject jugador;
	private Transform transformacion;
	//control de velocidad de la vala
	public float bulletSpeed;
	//Tiempo de vida de una vala
	public float bulletLife;
	Animator anim;
	Vector2 mov;
	float speed = 1f;

	void Awake(){
		buletRb = GetComponent<Rigidbody2D> ();
		/*jugador = GameObject.FindGameObjectWithTag ("Player");
		transformacion = jugador.transform;*/
	}

	// Use this for initialization
	void Start () {
		
		/**/
		anim = GetComponent<Animator> ();
	}
	float x = 0;
	// Update is called once per frame
	void Update () {
		x+=0.5f;
		mov = new Vector2 (
			x,
			buletRb.velocity.y
		);
		/*if (transformacion.localScale.x > 0) {
			buletRb.velocity = new Vector2 (bulletSpeed, buletRb.velocity.y);
			transform.localScale = new Vector3 (1, 1, 1);
		} else {
			buletRb.velocity = new Vector2 (-bulletSpeed, buletRb.velocity.y);
			transform.localScale = new Vector3 (-1, 1, 1);
		}*/
	}

	void FixedUpdate(){
		buletRb.MovePosition (buletRb.position + mov * speed * Time.deltaTime);
	}


	void OnCollisionEnter2D(Collision2D collision) {
		if (collision.gameObject.tag != "player") {
			anim.SetBool ("destroy", true);
			Destroy (gameObject, 1f);
		}
	}
}
