예제 #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;
        }
    }
예제 #2
0
파일: AICycle.cs 프로젝트: uchr/ld32
    public void AttackTroop()
    {
        Unit goalUnit = GetEnemy(troop.center);

        if (goalUnit != null)
        {
            this.goalUnit = goalUnit;
            troop.AttackUnit(goalUnit);
            isGoal = true;
            return;
        }

        Building goalBuilding = GetBuilding(troop.center);

        if (goalBuilding != null)
        {
            this.goalBuilding = goalBuilding;
            troop.AttackBuilding(goalBuilding);
            isGoal = true;
        }
    }