Exemple #1
0
    // bool waterMoving;
    #endregion


    void Update()
    {
        activeUnit = GameManager.instance.activeUnit;
        // projectile = GameManager.instance.projectile;

        if (gameActive)
        {
            if (!EventSystem.current.IsPointerOverGameObject() && activeUnit)
            {
                switch (activeUnit.unitAction)
                {
                case (HexUnit.UnitAction.Idle):
                    break;

                case (HexUnit.UnitAction.Move):
                    if (Input.GetMouseButtonDown(0))
                    {
                        DoMove();
                    }
                    else if (activeUnit.movement != 0)
                    {
                        DoPathfinding();
                    }
                    else
                    {
                    }
                    break;

                case (HexUnit.UnitAction.Attack):
                    UpdateCurrentCell();
                    if (currentCell.Distance == 1)                 //Change this to unitrange later
                    {
                        if (Input.GetMouseButtonDown(0) && currentCell.Unit && currentCell.Unit != activeUnit)
                        {
                            activeUnit.DoAttack(currentCell);
                        }
                    }
                    break;

                case (HexUnit.UnitAction.RangedAttack):
                    UpdateCurrentCell();

                    if (currentCell.Distance <= 3 && Input.GetMouseButtonDown(0) && currentCell.Unit && currentCell.Unit != activeUnit)     //this one as well
                    {
                        gameManager         = GameManager.instance;
                        CellToBeManipulated = currentCell;
                        TargetedCells.Add(activeUnit.Location);
                        TargetedCells.Add(CellToBeManipulated);
                        activeUnit.TurnToDoAction(CellToBeManipulated);
                        grid.ClearPath();
                        gameManager.CreateProjectile(TargetedCells, 10);

                        // TargetedCells.Clear();
                        NewButtonPressed();
                        SetIdle();
                    }
                    break;

                case (HexUnit.UnitAction.Earth):
                    UpdateCurrentCell();
                    if (currentCell.Distance <= 2 && !currentCell.IsUnderwater && Input.GetMouseButtonDown(0))     //this one as well
                    {
                        CellToBeManipulated = currentCell;
                        elevationSlider.gameObject.GetComponentInChildren <Slider>().value = cellToBeManipulated.Elevation;
                        elevationSlider.gameObject.SetActive(true);
                        elevationSlider.sliderUpdateActivate();
                        activeUnit.TurnToDoAction(CellToBeManipulated);
                        grid.ClearPath();
                        grid.SearchInRange(CellToBeManipulated, 0, 1);
                    }

                    break;

                case (HexUnit.UnitAction.Water):
                    UpdateCurrentCell();

                    // Debug.Log(Input.GetKey("left shift"));

                    if (currentCell.IsUnderwater && currentCell.Distance <= 3 && Input.GetMouseButtonDown(0) && Input.GetKey("left shift") && numberOfWaterCells != 0)
                    {
                        CellToBeManipulated = currentCell;
                        activeUnit.TurnToDoAction(CellToBeManipulated);
                        TargetedCells.Add(CellToBeManipulated);
                        numberOfWaterCells++;
                        grid.ClearPath();
                        grid.SearchInRange(CellToBeManipulated, 0, 1);
                        gameManager.CreateProjectile(TargetedCells, 0);

                        NewButtonPressed();
                        SetIdle();
                    }

                    else if (currentCell.Distance <= 3 && Input.GetMouseButtonDown(0))
                    {
                        CellToBeManipulated = currentCell;


                        if (currentCell.IsUnderwater && numberOfWaterCells < 4 && previousCell != CellToBeManipulated)
                        {
                            gameManager = GameManager.instance;
                            activeUnit.TurnToDoAction(CellToBeManipulated);
                            grid.ClearPath();
                            grid.SearchInRange(CellToBeManipulated, 3, 1);
                            // TargetedWaterCells[numberOfWaterCells] = CellToBeManipulated;
                            TargetedCells.Add(CellToBeManipulated);
                            numberOfWaterCells++;
                            previousCell = currentCell;
                        }

                        if (currentCell.IsUnderwater && numberOfWaterCells == 4)
                        {
                            activeUnit.TurnToDoAction(CellToBeManipulated);
                            grid.ClearPath();
                            grid.SearchInRange(CellToBeManipulated, 0, 1);
                            gameManager.CreateProjectile(TargetedCells, 0);

                            NewButtonPressed();
                            SetIdle();
                        }

                        if (!currentCell.IsUnderwater && !currentCell.Unit && numberOfWaterCells >= 1 && TargetedCells[0].Elevation >= CellToBeManipulated.Elevation)
                        {
                            TargetedCells.Add(CellToBeManipulated);
                            numberOfWaterCells++;
                            activeUnit.TurnToDoAction(CellToBeManipulated);
                            grid.ClearPath();
                            grid.SearchInRange(CellToBeManipulated, 0, 1);
                            gameManager.CreateProjectile(TargetedCells, 1);

                            NewButtonPressed();
                            SetIdle();
                        }
                    }


                    break;
                }
            }
            if (Input.GetKey(KeyCode.Escape))
            {
                elevationSlider.sliderUpdateDeActivate();
                elevationSlider.gameObject.SetActive(false);
                SetIdle();
            }
        }
    }