Exemplo n.º 1
0
    private void HandleConnecting()
    {
        Tower hoveredTower = GetHoveredTarget <Tower>();

        if (hoveredTower != null)
        {
            indicator.ShowAt(hoveredTower.transform.position);
            lineFollow.SetEnd(hoveredTower.transform.position);

            if (currentEnergy.CurrentTower == hoveredTower)
            {
                lineFollow.ShowNormal();
                indicator.ShowNormal();
                if (LeftClick)
                {
                    lineFollow.Hide();
                    currentEnergy = null;
                    UIManager.main.ClearEnergyIndicators();
                }
            }
            else if (hoveredTower.AcceptConnections)
            {
                lineFollow.ShowNormal();
                indicator.ShowNormal();
                if (LeftClick)
                {
                    hoveredTower.ReserveEnergy(currentEnergy);
                    currentEnergy.Connect(hoveredTower);
                    currentEnergy = null;
                    lineFollow.Hide();
                    indicator.Hide();
                    UIManager.main.ClearEnergyIndicators();
                }
            }
            else
            {
                lineFollow.ShowError();
                indicator.ShowError();
            }
        }
        else
        {
            indicator.Hide();
            lineFollow.ShowNormal();
            indicator.ShowNormal();
            bool mouseHitGround = Tools.MouseCast(out hit, groundLayer);
            if (mouseHitGround)
            {
                lineFollow.SetEnd(hit.point);
            }
            if (LeftClick)
            {
                currentEnergy.Disconnect();
                lineFollow.Hide();
                currentEnergy = null;
                UIManager.main.ClearEnergyIndicators();
            }
        }
        if (RightClick || CancelKeyDown)
        {
            lineFollow.Hide();
            currentEnergy = null;
            UIManager.main.ClearEnergyIndicators();
        }
    }