private void DetectClickOnMachines()
    {
        if (!TouchHelpers.IsTouchingOrClickingOverUI())
        {
            Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);

            if (hit && hit.transform.tag == "machine")
            {
                Machine machine_hit = hit.transform.GetComponent <Machine>();;
                if (machine_hit.machineController.IsThereMoreThanOneTeamAlive())
                {
                    if (selectedMachine == null)
                    {
                        if (machine_hit.team == TeamHelpers.Team.HUMAN_TEAM)
                        {
                            SelectMachine(machine_hit);
                        }
                    }
                    else
                    {
                        if (selectedMachine == machine_hit)
                        {
                            DeselectAllMachines();
                        }
                        else
                        {
                            SelectMachine(machine_hit);
                        }
                    }
                }
            }

            if (selectedMachine != null && targetMachine != null)
            {
                AttackMachine();
            }
        }
    }
示例#2
0
    private void DetectClickOnTiles()
    {
        if (!TouchHelpers.IsTouchingOrClickingOverUI())
        {
            Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);

            if (hit)
            {
                DesactiveAllMenus();

                if (hit.transform.tag == "floor")
                {
                    if (hit.transform.gameObject == selectedFloor)
                    {
                        DeselectCurrentFloor();
                        return;
                    }

                    if (selectedFloor != null)
                    {
                        if (typeOfConnectionToCreate != null)
                        {
                            Floor current_floor = CurrentSelectedFloor();
                            Floor another_floor = hit.transform.GetComponent <Floor>();

                            if (current_floor.IsHoldingSomething() &&
                                another_floor.IsHoldingSomething() &&
                                !machineController.IsThereConnectionBetween(current_floor.objectHolded,
                                                                            another_floor.objectHolded))
                            {
                                CreateConnectionBetweenMachinesOn(selectedFloor,
                                                                  hit.transform.gameObject,
                                                                  ConnectionPreFabByType(typeOfConnectionToCreate),
                                                                  ConnectionsOnMachines().Count);
                                ConnectionModeOff();
                                DeselectCurrentFloor();
                                return;
                            }
                        }

                        DeselectCurrentFloor();
                    }

                    SelectFloor(hit.transform.gameObject);

                    if (IsCurrentSelectedFloorHoldingSomething())
                    {
                        switch (selectedFloor.GetComponent <Floor>().objectHolded.tag)
                        {
                        case "machine":
                        {
                            ActiveMachineEditorMenu(true);
                            break;
                        }

                        case "decoration":
                        {
                            ActiveDecorationEditorMenu(true);
                            break;
                        }
                        }
                    }
                    else
                    {
                        ActiveFloorEditorMenu(true);
                    }
                }
                else
                {
                    DeselectCurrentFloor();
                }
            }
        }
    }