﻿using UnityEngine;
using System.Collections;

public class GunController : MonoBehaviour {
	
	public GameObject bala;
	public int velocidadbala;
	private Vector3 balapos = new Vector3 (0,0,0);

	private Vector3 player_pos;
	private Vector3 object_pos;
	private float angle;
	private GameObject[] player;


	void FixedUpdate () {    

		player = GameObject.FindGameObjectsWithTag ("Player");

		player_pos = player [0].transform.position;

		object_pos = transform.position;Camera.main.WorldToScreenPoint (transform.position);

		player_pos.x = player_pos.x - object_pos.x;
		player_pos.y = player_pos.y - object_pos.y;
		player_pos.z = 0.0f;

		angle = Mathf.Atan2 (player_pos.y, player_pos.x) * Mathf.Rad2Deg - 180;
		Vector3 rotationVector = new Vector3 (0, 0, angle);
		transform.rotation = Quaternion.Euler (rotationVector);
			
	}
}