void CheckUnitOBJ(GameObject hitObject) { UnitStatSystem unit = hitObject.GetComponent <UnitStatSystem>(); if (unit != null) { Debug.Log("SELECT UNIT"); if (unit.GetUnitType() == UnitStatSystem.UnitObjectType.Building) { Debug.Log("SELECT Building"); BuildingSystem buil = hitObject.GetComponent <BuildingSystem>(); if (player.GetPlayerNumber() == buil.GetOwner()) { Debug.Log("Select Own Building"); UnselectUnit(); UnselectWorker(); if (buil != selectedBuilding) { UnselectBuilding(); SelectBuilding(buil); } } } if (unit.GetUnitType() == UnitStatSystem.UnitObjectType.Units) { WorkerUnit wor = unit.GetComponent <WorkerUnit>(); if (wor != null) { if (player.GetPlayerNumber() == wor.GetOwner()) { UnselectUnit(); UnselectBuilding(); if (wor != selectedWorker) { UnselectWorker(); SelectWorker(wor); } } } } if (unit.GetOwner() != player.GetPlayerNumber() && selectedUnit != null) { if (!AllianceSystem.CheckAlly(player.GetPlayerNumber(), unit.GetOwner())) { Debug.Log("ATTACK"); selectedUnit.SetAutoAttaack(true); selectedUnit.SetTarget(unit.gameObject); } } } if (hitObject.tag == "Soldier Group") { Debug.Log("SELECT SOLDIER"); UnitGroupSystem unitGro = hitObject.GetComponent <UnitGroupSystem>(); if (player.GetPlayerNumber() == unitGro.GetOwner()) { Debug.Log("Select own Soldier"); UnselectBuilding(); UnselectWorker(); if (unitGro != selectedUnit) { UnselectUnit(); SelectUnit(unitGro); } } if (unitGro.GetOwner() != player.GetPlayerNumber() && selectedUnit != null) { if (!AllianceSystem.CheckAlly(player.GetPlayerNumber(), unitGro.GetOwner())) { Debug.Log("ATTACK"); selectedUnit.SetAutoAttaack(true); selectedUnit.SetTarget(unitGro.gameObject); } } } }