private void CheckTowerAssignment() { Vector3 mousePos = cam.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(new Vector2(mousePos.x, mousePos.y), Vector2.zero, 0, TowerLayers); if (hit) { Tower tempTower = hit.collider.gameObject.GetComponent <Tower>(); TroopPlaceholder temp; if (tempTower.isUnitAssigned) { temp = tempTower.RemoveUnit(); if (!inventory.AddTroop(temp)) { tempTower.AssignUnit(temp); } } else { temp = inventory.PopHighlightedTroop(); if (temp != null) { tempTower.AssignUnit(temp); } } } }