Beispiel #1
0
    protected new void Update()
    {
        if (!iaControlled)
        {
            if (!mouseOverUI)
            {
                if (mouseBehav == MOUSE_ACTION_FINAL.SELECT)
                {
                    if (Input.GetMouseButton(0))
                    {
                        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                        {
                            RaycastHit hit;
                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                            {
                                PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                                if (!selectedUnits.Contains(character))
                                {
                                    character.selected = true;
                                    characterWithFocus = character;
                                    selectedUnits.Add(character);
                                    ui.showDebugInfo(true);
                                    (ui as UIManagerFinal).actualizeAgentDebugInfo(characterWithFocus);
                                }
                                else
                                {
                                    character.selected = false;
                                    if (character == characterWithFocus)
                                    {
                                        characterWithFocus = null;
                                        ui.showDebugInfo(false);
                                    }
                                    selectedUnits.Remove(character);
                                }
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                            {
                                PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>();
                                if (character != characterWithFocus)
                                {
                                    characterWithFocus = character;
                                    ui.showDebugInfo(true);
                                    ui.actualizeAgentDebugInfo(character);
                                }
                            }
                        }
                        else
                        {
                            foreach (PersonajePlayer person in selectedUnits)
                            {
                                person.selected = false;
                            }
                            selectedUnits.Clear();
                            RaycastHit hit;
                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                            {
                                PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                                character.selected = true;
                                characterWithFocus = character;
                                selectedUnits.Add(character);
                                ui.showDebugInfo(true);
                                (ui as UIManagerFinal).actualizeAgentDebugInfo(characterWithFocus);
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                            {
                                PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>();
                                if (character != characterWithFocus)
                                {
                                    characterWithFocus = character;
                                    ui.showDebugInfo(true);
                                    ui.actualizeAgentDebugInfo(character);
                                }
                            }
                            else
                            {
                                if (characterWithFocus != null)
                                {
                                    characterWithFocus = null;
                                    ui.showDebugInfo(false);
                                }
                            }
                        }
                        ui.actualizeUserButtons(allPossibleActions());
                    }
                }
                else if (mouseBehav == MOUSE_ACTION_FINAL.MOVE)
                {
                    if (selectedUnits.Count > 0)
                    {
                        if (Input.GetMouseButton(0))
                        {
                            RaycastHit hit;

                            /*if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 9))
                             * {
                             *  return;
                             * }
                             * else */

                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                            {
                                PersonajeBase enemigo = hit.collider.GetComponent <PersonajeBase>();
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    AccionCompuesta ac = TacticalModule.createAttackingAction(person, enemigo);
                                    if (person.currentFormacion != null)
                                    {
                                        Formacion formation = person.currentFormacion;
                                        if (person.currentFormacion.lider == person)
                                        {
                                            formation.disbandGrid();
                                            for (int i = 0; i < formation.getMiembros.Length; i++)
                                            {
                                                if (formation.getMiembros[i] != null)
                                                {
                                                    AccionCompuesta attackMachaka = TacticalModule.createAttackingAction(formation.getMiembros[i], enemigo);
                                                    formation.getMiembros[i].accion = attackMachaka;
                                                    formation.getMiembros[i].accion.doit();
                                                }
                                            }
                                            formaciones.Remove(formation);
                                        }
                                        else
                                        {
                                            formation.removeMiembro(person);
                                            person.currentFormacion = null;
                                            person.accion           = ac;
                                            person.accion.doit();
                                        }
                                    }
                                    else
                                    {
                                        person.accion = ac;
                                        person.accion.doit();
                                    }
                                }
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 14))
                            {
                                Vector2 baseToGo = positionToGrid(hit.collider.transform.parent.position);
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    ActionGo gotobase = new ActionGo(person, TacticalModule.getUnitPointOnBaseStatic(person, baseToGo, gm.getAllies()), null);
                                    if (person.currentFormacion != null)
                                    {
                                        Formacion formation = person.currentFormacion;
                                        if (person.currentFormacion.lider == person)
                                        {
                                            formation.disbandGrid();
                                            for (int i = 0; i < formation.getMiembros.Length; i++)
                                            {
                                                if (formation.getMiembros[i] != null)
                                                {
                                                    ActionGo gotobaseMachakas = new ActionGo(formation.getMiembros[i], TacticalModule.getUnitPointOnBaseStatic(formation.getMiembros[i], baseToGo, gm.getAllies()), null);
                                                    formation.getMiembros[i].accion = gotobaseMachakas;
                                                    formation.getMiembros[i].accion.doit();
                                                }
                                            }
                                            formaciones.Remove(formation);
                                        }
                                        else
                                        {
                                            formation.removeMiembro(person);
                                            person.currentFormacion = null;
                                            person.accion           = gotobase;
                                            person.accion.doit();
                                        }
                                    }
                                    else
                                    {
                                        person.accion = gotobase;
                                        person.accion.doit();
                                    }
                                }
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10))
                            {
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    Vector2 posicionDestino = positionToGrid(hit.point);
                                    Vector2 posicionOrigen  = positionToGrid(person.posicion);

                                    ActionGo moverse = new ActionGo(person, posicionDestino, null);

                                    if (person.currentFormacion != null)
                                    {
                                        Formacion formation = person.currentFormacion;
                                        if (person.currentFormacion.lider != person)
                                        {
                                            formation.removeMiembro(person);
                                            person.currentFormacion = null;
                                        }
                                        person.accion = moverse;
                                        person.accion.doit();
                                    }
                                    else
                                    {
                                        person.accion = moverse;
                                        person.accion.doit();
                                    }
                                }
                            }
                        }
                    }
                }
                else if (mouseBehav == MOUSE_ACTION_FINAL.FORM_T || mouseBehav == MOUSE_ACTION_FINAL.FORM_S || mouseBehav == MOUSE_ACTION_FINAL.FORM_R)
                {
                    if (selectedUnits.Count > 0)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            RaycastHit hit;
                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                            {
                                // PARA FORMACIONES
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    if (person.currentFormacion != null)
                                    {
                                        formaciones.Remove(person.currentFormacion);
                                        person.currentFormacion.disbandGrid();
                                    }
                                }
                                //Asignamos el lider que clicamos
                                PersonajeBase lider = hit.collider.gameObject.GetComponent <PersonajeBase>();

                                Formacion formacion = null;

                                switch (mouseBehav)
                                {
                                case MOUSE_ACTION_FINAL.FORM_T:
                                    formacion = new FormacionTriangulo(lider);
                                    break;

                                case MOUSE_ACTION_FINAL.FORM_S:
                                    formacion = new FormacionCuadrado(lider);
                                    break;

                                case MOUSE_ACTION_FINAL.FORM_R:
                                    formacion = new FormacionPorRoles(lider);
                                    break;
                                }
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    person.currentFormacion = formacion;
                                    formacion.addMiembro(person);
                                }
                                lider.currentFormacion = formacion;
                                formacion.formacionASusPuestosAccion();
                                //formacion.formacionASusPuestos();
                                formaciones.Add(formacion);
                            }
                        }
                    }
                }
                else if (mouseBehav == MOUSE_ACTION_FINAL.ROUTE_SET)
                {
                    if (selectedUnits.Count > 0)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            RaycastHit hit;
                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 11))
                            {
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    if (person.currentFormacion != null)
                                    {
                                        formaciones.Remove(person.currentFormacion);
                                        person.currentFormacion.disbandGrid();
                                    }
                                }
                                setRouteOnUnits();
                                pathToSet.Clear();
                                setMouseBehaviour(0);
                                ui.selectMouseOption(0);
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10))
                            {
                                if (pathToSet.Count == 0)
                                {
                                    foreach (PersonajeBase unit in selectedUnits)
                                    {
                                        foreach (Transform routeElem in unit.routeMarks)
                                        {
                                            Destroy(routeElem.gameObject);
                                        }
                                    }
                                }
                                pathToSet.Add(hit.point);
                                foreach (PersonajeBase unit in selectedUnits)
                                {
                                    GameObject routeMark = Instantiate(routeMarkPrefab, unit.routeMarks);
                                    routeMark.transform.position = new Vector3(hit.point.x, 0.05f, hit.point.z);
                                    if (pathToSet.Count > 1)
                                    {
                                        GameObject routeLine = Instantiate(routeLinePrefab, unit.routeMarks);
                                        routeLine.GetComponent <FlechaDeRutaDelegate>().setRouteDirection(pathToSet[pathToSet.Count - 2], pathToSet[pathToSet.Count - 1]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            if (Input.GetMouseButton(0))
            {
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    RaycastHit hit;
                    if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                    {
                        PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                        if (!selectedUnits.Contains(character))
                        {
                            character.selected = true;
                            characterWithFocus = character;
                            selectedUnits.Add(character);
                            ui.showDebugInfo(true);
                            ui.actualizeAgentDebugInfo(character);
                        }
                        else
                        {
                            character.selected = false;
                            if (character == characterWithFocus)
                            {
                                characterWithFocus = null;
                                ui.showDebugInfo(false);
                            }
                            selectedUnits.Remove(character);
                        }
                    }
                    else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                    {
                        PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>();
                        if (character != characterWithFocus)
                        {
                            characterWithFocus = character;
                            ui.showDebugInfo(true);
                            ui.actualizeAgentDebugInfo(character);
                        }
                    }
                }
                else
                {
                    foreach (PersonajePlayer person in selectedUnits)
                    {
                        person.selected = false;
                    }
                    selectedUnits.Clear();
                    RaycastHit hit;
                    if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                    {
                        PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                        character.selected = true;
                        characterWithFocus = character;
                        selectedUnits.Add(character);
                        ui.showDebugInfo(true);
                        ui.actualizeAgentDebugInfo(character);
                    }
                    else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                    {
                        PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>();
                        if (character != characterWithFocus)
                        {
                            characterWithFocus = character;
                            ui.showDebugInfo(true);
                            ui.actualizeAgentDebugInfo(character);
                        }
                    }
                    else
                    {
                        if (characterWithFocus != null)
                        {
                            characterWithFocus = null;
                            ui.showDebugInfo(false);
                        }
                    }
                }
            }
        }
    }
    protected new void Update()
    {
        if (!mouseOverUI)
        {
            if (mouseBehav == MOUSE_ACTION_FORMATION.SELECT)
            {
                if (Input.GetMouseButton(0))
                {
                    if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                        {
                            PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                            if (!selectedUnits.Contains(character))
                            {
                                character.selected = true;
                                characterWithFocus = character;
                                selectedUnits.Add(character);
                                ui.showDebugInfo(true);
                                ui.actualizeAgentDebugInfo(character);
                            }
                            else
                            {
                                character.selected = false;
                                if (character == characterWithFocus)
                                {
                                    characterWithFocus = null;
                                    ui.showDebugInfo(false);
                                }
                                selectedUnits.Remove(character);
                            }
                        }
                    }
                    else
                    {
                        foreach (PersonajePlayer person in selectedUnits)
                        {
                            person.selected = false;
                        }
                        selectedUnits.Clear();
                        RaycastHit hit;
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                        {
                            PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                            character.selected = true;
                            characterWithFocus = character;
                            selectedUnits.Add(character);
                            ui.showDebugInfo(true);
                            ui.actualizeAgentDebugInfo(character);
                        }
                        else
                        {
                            if (characterWithFocus != null)
                            {
                                characterWithFocus = null;
                                ui.showDebugInfo(false);
                            }
                        }
                    }
                }
            }
            else if (mouseBehav == MOUSE_ACTION_FORMATION.MOVE)
            {
                if (selectedUnits.Count > 0)
                {
                    if (Input.GetMouseButton(0))
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                        {
                            PersonajeBase personajeObjetivo = hit.collider.gameObject.GetComponent <PersonajeBase>();
                            foreach (PersonajeBase person in selectedUnits)
                            {
                                if (person.currentFormacion != null)
                                {
                                    formaciones.Remove(person.currentFormacion);
                                    person.currentFormacion.disband();
                                }
                                PursueSD pursueSD = new PursueSD();
                                pursueSD.target = personajeObjetivo;

                                /*person.fake.posicion = hit.point;
                                 * person.fake.moveTo(hit.point);
                                 * person.fake.innerDetector = person.innerDetector;*/
                                person.newTask(pursueSD);
                            }
                        }
                        else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10))
                        {
                            foreach (PersonajeBase person in selectedUnits)
                            {
                                if (person.currentFormacion != null && person.currentFormacion.lider != person)
                                {
                                    formaciones.Add(person.currentFormacion);
                                    person.currentFormacion.disband();
                                }
                                //person.setAction(new AgentActionMove(new Vector2(hit.point.x, hit.point.z), person.innerDetector, person.outterDetector));
                                PursueSD pursueSD = new PursueSD();
                                pursueSD.target = person.fakeMovement;
                                person.fakeMovement.posicion = hit.point;
                                person.fakeMovement.moveTo(hit.point); // mover los fakes para debuggeo
                                person.fakeMovement.innerDetector = person.innerDetector;
                                person.newTask(pursueSD);
                            }
                        }
                    }
                }
            }
            else
            {
                if (Input.GetMouseButton(0))
                {
                    RaycastHit hit;
                    if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                    {
                        foreach (PersonajeBase person in selectedUnits)
                        {
                            if (person.currentFormacion != null)
                            {
                                formaciones.Remove(person.currentFormacion);
                                person.currentFormacion.disband();
                            }
                        }
                        //Asignamos el lider que clicamos
                        PersonajeBase lider     = hit.collider.gameObject.GetComponent <PersonajeBase>();
                        Formacion     formacion = null;
                        if (mouseBehav == MOUSE_ACTION_FORMATION.TRIANGLE_FORMATION)
                        {
                            formacion = new FormacionTriangulo(lider);
                        }
                        else if (mouseBehav == MOUSE_ACTION_FORMATION.SQUARE_FORMATION)
                        {
                            formacion = new FormacionCuadrado(lider);
                        }
                        else if (mouseBehav == MOUSE_ACTION_FORMATION.ROLE_FORMATION)
                        {
                            formacion = new FormacionPorRoles(lider);
                        }
                        foreach (PersonajeBase person in selectedUnits)
                        {
                            person.currentFormacion = formacion;
                            if (person != lider)
                            {
                                formacion.addMiembro(person);
                            }
                        }
                        formacion.formacionASusPuestos();
                        formaciones.Add(formacion);
                    }
                }
            }
        }
    }
    protected void Update()
    {
        //INPUT MANAGEMENT
        //CAMERA INPUT HERE (AROUND THE MAP)


        if (!mouseOverUI)
        {
            if (mouseBehav == MOUSE_ACTION.SELECT)
            {
                if (Input.GetMouseButton(0))
                {
                    if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                        {
                            PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                            if (!selectedUnits.Contains(character))
                            {
                                character.selected = true;
                                characterWithFocus = character;
                                selectedUnits.Add(character);
                                ui.showDebugInfo(true);
                                ui.actualizeAgentDebugInfo(character);
                            }
                            else
                            {
                                character.selected = false;
                                if (character == characterWithFocus)
                                {
                                    characterWithFocus = null;
                                    ui.showDebugInfo(false);
                                }
                                selectedUnits.Remove(character);
                            }
                        }
                        ui.actualizeUserButtons(allPossibleActions());
                    }
                    else
                    {
                        foreach (PersonajePlayer person in selectedUnits)
                        {
                            person.selected = false;
                        }
                        selectedUnits.Clear();
                        RaycastHit hit;
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                        {
                            PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                            character.selected = true;
                            characterWithFocus = character;
                            selectedUnits.Add(character);
                            ui.showDebugInfo(true);
                            ui.actualizeAgentDebugInfo(character);
                        }
                        else
                        {
                            if (characterWithFocus != null)
                            {
                                characterWithFocus = null;
                                ui.showDebugInfo(false);
                            }
                        }
                        ui.actualizeUserButtons(allPossibleActions());
                    }
                }
            }
            else if (mouseBehav == MOUSE_ACTION.MOVE)
            {
                if (selectedUnits.Count > 0)
                {
                    if (Input.GetMouseButton(0))
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                        {
                            PersonajeBase personajeObjetivo = hit.collider.gameObject.GetComponent <PersonajeBase>();
                            foreach (PersonajeBase person in selectedUnits)
                            {
                                if (person.currentFormacion != null && person.currentFormacion.lider != person)
                                {
                                    formaciones.Remove(person.currentFormacion);
                                    person.currentFormacion.disband();
                                }
                                PursueSD pursueSD = new PursueSD();
                                pursueSD.target = personajeObjetivo;

                                /*person.fake.posicion = hit.point;
                                 * person.fake.moveTo(hit.point);
                                 * person.fake.innerDetector = person.innerDetector;*/
                                person.newTask(pursueSD);
                            }
                        }
                        else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10))
                        {
                            foreach (PersonajeBase person in selectedUnits)
                            {
                                if (person.currentFormacion != null && person.currentFormacion.lider != person)
                                {
                                    formaciones.Remove(person.currentFormacion);
                                    person.currentFormacion.disband();
                                }
                                PursueSD pursueSD = new PursueSD();
                                pursueSD.target = person.fakeMovement;
                                person.fakeMovement.posicion = hit.point;
                                person.fakeMovement.moveTo(hit.point); // mover los fakes para debuggeo
                                person.fakeMovement.innerDetector = person.innerDetector;
                                person.newTask(pursueSD);
                            }
                        }
                    }
                }
            }
            else if (mouseBehav == MOUSE_ACTION.FORM_T || mouseBehav == MOUSE_ACTION.FORM_S || mouseBehav == MOUSE_ACTION.FORM_R)
            {
                if (selectedUnits.Count > 0)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                        {
                            // PARA FORMACIONES
                            foreach (PersonajeBase person in selectedUnits)
                            {
                                if (person.currentFormacion != null)
                                {
                                    formaciones.Add(person.currentFormacion);
                                    person.currentFormacion.disband();
                                }
                            }
                            //Asignamos el lider que clicamos
                            PersonajeBase lider = hit.collider.gameObject.GetComponent <PersonajeBase>();

                            Formacion formacion = null;

                            switch (mouseBehav)
                            {
                            case MOUSE_ACTION.FORM_T:
                                formacion = new FormacionTriangulo(lider);
                                break;

                            case MOUSE_ACTION.FORM_S:
                                formacion = new FormacionCuadrado(lider);
                                break;

                            case MOUSE_ACTION.FORM_R:
                                formacion = new FormacionPorRoles(lider);
                                break;
                            }
                            foreach (PersonajeBase person in selectedUnits)
                            {
                                person.currentFormacion = formacion;
                                if (person != lider)
                                {
                                    formacion.addMiembro(person);
                                }
                            }
                            formacion.formacionASusPuestos();
                            formaciones.Add(formacion);


                            //PARA FLOCKING

                            /*PersonajeBase lider = hit.collider.gameObject.GetComponent<PersonajeBase>();
                             * foreach (PersonajeBase person in selectedUnits)
                             * {
                             *  if (person!= lider)
                             *  {
                             *      FlockingSD flocking = new FlockingSD(1,1,1);
                             *      flocking.target = lider;
                             *      person.newTask(flocking);
                             *  }
                             * }*/
                        }
                    }
                }
            }
            else if (mouseBehav == MOUSE_ACTION.ROUTE_SET)
            {
                if (selectedUnits.Count > 0)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 11))
                        {
                            setRouteOnUnits();
                            pathToSet.Clear();
                            setMouseBehaviour(0);
                            ui.selectMouseOption(0);

                            /*foreach (PersonajeBase person in selectedUnits)
                             * {
                             *  if (person.currentFormacion != null)
                             *  {
                             *      formationManager.removeFormacion(person.currentFormacion);
                             *      person.currentFormacion.disband();
                             *  }
                             * }*/
                        }
                        else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10))
                        {
                            if (pathToSet.Count == 0)
                            {
                                foreach (PersonajeBase unit in selectedUnits)
                                {
                                    foreach (Transform routeElem in unit.routeMarks)
                                    {
                                        Destroy(routeElem.gameObject);
                                    }
                                }
                            }
                            pathToSet.Add(hit.point);
                            foreach (PersonajeBase unit in selectedUnits)
                            {
                                GameObject routeMark = Instantiate(routeMarkPrefab, unit.routeMarks);
                                routeMark.transform.position = new Vector3(hit.point.x, 0.05f, hit.point.z);
                                if (pathToSet.Count > 1)
                                {
                                    GameObject routeLine = Instantiate(routeLinePrefab, unit.routeMarks);
                                    routeLine.GetComponent <FlechaDeRutaDelegate>().setRouteDirection(pathToSet[pathToSet.Count - 2], pathToSet[pathToSet.Count - 1]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }