Beispiel #1
0
 void OnMouseDown()
 {
     //moves unit if space is not occupied
     if (!isOccupied && reachable)
     {
         graphicalBattlefield.moveUnit(logicalPos);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Method checks if attacking unit can attack it's target and finds where the attacking unit is to move to,
 /// assuming movement is necessary. Then calls upon the graphicalBattlefield to do the required action.
 /// </summary>
 /// <param name="cx">X coordinate of unit to be attacked</param>
 /// <param name="cy">Y coordinate of unit to be attacked</param>
 private void checkPos(int cx, int cy)
 {
     if (unitsOnField[cx, cy].GetComponent <UnitGameObject>().Attackable)//Checks if unit can be attacked
     {
         //Finds where it should move to attack incase of meele unit.
         GroundGameObject[] neighbours = findNeighboursHex(cx, cy);
         Point tmpGoal = neighbours[0].LogicalPos;
         if (!neighbours[0].Reachable)
         {
             for (int i = 1; i < neighbours.Length; i++)
             {
                 if (neighbours[i] == null)
                 {
                     break;
                 }
                 if (neighbours[i].Reachable)
                 {
                     tmpGoal = neighbours[i].LogicalPos;
                     break;
                 }
             }
         }
         graphicalBattlefield.attackUnit(unitsOnField[cx, cy].GetComponent <UnitGameObject>(), tmpGoal);
     }
     else
     {
         //Finds closest position to target that it can reach.
         while (!field[cx, cy].GetComponent <GroundGameObject>().Reachable)
         {
             if (cx < x)
             {
                 cx++;
             }
             else if (cx > x)
             {
                 cx--;
             }
             if (cy < y)
             {
                 cy++;
             }
             else if (cy > y)
             {
                 cy--;
             }
         }
         graphicalBattlefield.moveUnit(new Point(cx, cy));
     }
 }