Ejemplo n.º 1
0
    private void SelectedTroop()
    {
        UpdatePointer();

        if (!EventSystem.current.IsPointerOverGameObject() && !isSelectionArea)
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 50.0f, 1 << 8))               // Torus layer
            {
                if (Input.GetMouseButtonDown(1))
                {
                    if (Physics.Raycast(ray, out hit, 50.0f, 1 << 11))                       // Units layer
                    {
                        var unit = hit.transform.GetComponent <Unit>();
                        if (unit.owner == 1)
                        {
                            troop.AttackUnit(unit);
                            return;
                        }
                    }

                    if (Physics.Raycast(ray, out hit, 50.0f, 1 << 10))                       // Building layer
                    {
                        var building = hit.transform.GetComponent <Building>();
                        if (building.owner == 1)
                        {
                            troop.AttackBuilding(building);
                            return;
                        }
                    }

                    if (Physics.Raycast(ray, out hit, 50.0f, 1 << 8))                       // Torus layer
                    {
                        troop.Move(torus.CartesianToTorus(hit.point));
                        return;
                    }
                }
            }
        }

        EventSelection eventSelection = Select();

        if (eventSelection == EventSelection.Selected)
        {
            return;
        }
        if (eventSelection == EventSelection.Unselected)
        {
            Unselect();
            return;
        }
    }