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

public class UnitBehavior : MonoBehaviour {
	private DeployedUnit unit;

	void OnMouseDown() {
		//GameController.leftClick(unit);
	}

	void OnMouseOver() {
		if (Input.GetMouseButtonDown(1)) {
			GameController.rightClick(unit);
		}

		unit.setMouseOver(true);
	}

	void OnMouseExit() {
		unit.setMouseOver(false);
	}

	void OnTriggerStay(Collider other) {
		/*if (other.gameObject.layer == 10) { //only units

			DeployedUnit otherUnit = other.gameObject.GetComponent<UnitBehavior>().unit;

			if (unit == null || otherUnit == null) {
				return;
			}
			
			if (!unit.isStacked() && !otherUnit.isStacked()) { //only merge 'top level' units
				other.gameObject.GetComponent<UnitBehavior>().unit.setStackedParent(unit);
			}
		}*/
	}

	void OnTriggerExit(Collider other) {
		/*if (other.gameObject.layer == 10) { //only units

			if (unit == null) {
				return;
			}

			if (unit.getStackedParent() == other.gameObject.GetComponent<UnitBehavior>().unit) {
				unit.setStackedParent(null);

			}
		}*/
	}

	public void setUnit(DeployedUnit unit) {
		this.unit = unit;
	}
}