using UnityEngine;
using System.Collections;

public class GunCtrl : MonoBehaviour {

	public static GunCtrl instance;
	public GameObject[] guns;

	Transform target;
	Transform _transform;
	Camera cameramain;

	// Use this for initialization
	void Awake () {
		instance = this;
		target = null;
		_transform = transform;
		cameramain = Camera.main;
	}
	
	// Update is called once per frame
	void Update () {
		if(target!=null){
			_transform.up = _transform.position - target.position;
		}else{
			Vector3 mousePos = cameramain.ScreenToWorldPoint(Input.mousePosition);
			mousePos.z = 0;
			_transform.up = _transform.position - mousePos;
		}
	}

	public void EnableGun(Transform newTarget){
		target = newTarget;
	}

	public void DisableGun(){
		target = null;
	}

	public void Initialize(int gameMode){
		switch(gameMode){
		case 0:
			guns[0].SetActive(true);
			break;
		case 1:
			guns[1].SetActive(true);
			break;
		case 2:
			guns[2].SetActive(true);
			break;
		}
	}

}
