Example #1
0
 private void Update()
 {
     if (MoveCharacter)
     {
         character = turnManager.GetCharacterInTurn();
         character.transform.position = Vector3.Lerp(starterHex.transform.position, nextHex.transform.position, interpolationAmount);
         interpolationAmount         += Time.deltaTime * speed;
         if (character.transform.position == nextHex.transform.position)
         {
             starterHex.GetComponent <HexProperties>().CharacterInHex = null;
             nextHex.GetComponent <HexProperties>().CharacterInHex    = character;
             interpolationAmount = 0;
             starterHex          = MovementPath[0];
             MovementPath.RemoveAt(0);
             if (MovementPath.Count != 0)
             {
                 nextHex = MovementPath[0];
                 combatAnimationManager.TurnTowardsTarget(character, nextHex);
             }
             else
             {
                 MoveCharacter = false;
                 inputManager.ChangeCombatButtonsTo(true);
                 combatAnimationManager.MoveAnimation(character.GetComponent <Animator>(), false);
             }
         }
     }
 }
Example #2
0
    private IEnumerator MoveCharacter()
    {
        bool       moveCharacter       = true;
        float      interpolationAmount = 0.0f;
        float      speed = 3.0f;
        GameObject enemy = turnManager.GetCharacterInTurn();

        enemy = turnManager.GetCharacterInTurn();
        GameObject        enemyHex              = pathfinding.CharacterToHexPosition(enemy);
        Stats             enemyStats            = enemy.GetComponent <Stats>();
        List <GameObject> allPlayers            = GetAllPlayersInCombat();
        List <GameObject> shortestPathToAPlayer = new List <GameObject>();// shortestPathToAPlayer;
        GameObject        closestPlayer         = GetClosestAttackablePlayer(allPlayers, out shortestPathToAPlayer);
        GameObject        nextHex;

        if (shortestPathToAPlayer.Count > 0)
        {
            nextHex = shortestPathToAPlayer[0];
        }
        else
        {
            nextHex       = null;
            moveCharacter = false;
        }
        combatAnimationManager.TurnTowardsTarget(enemy, closestPlayer);
        while (moveCharacter)
        {
            combatAnimationManager.MoveAnimation(enemy.GetComponent <Animator>(), true);
            enemy.transform.position = Vector3.Lerp(enemyHex.transform.position, nextHex.transform.position, interpolationAmount);
            interpolationAmount     += Time.deltaTime * speed;
            if (enemy.transform.position == nextHex.transform.position)//chegou ao proximo hex
            {
                enemyStats.currentMove -= 1;
                enemyHex.GetComponent <HexProperties>().CharacterInHex = null;
                nextHex.GetComponent <HexProperties>().CharacterInHex  = enemy;
                interpolationAmount = 0;
                enemyHex            = shortestPathToAPlayer[0];
                shortestPathToAPlayer.RemoveAt(0);
                if (shortestPathToAPlayer.Count == 0 || enemyStats.currentMove == 0)
                {
                    moveCharacter = false;
                    combatAnimationManager.MoveAnimation(enemy.GetComponent <Animator>(), false);
                }
                else
                {
                    nextHex = shortestPathToAPlayer[0];
                    combatAnimationManager.TurnTowardsTarget(enemy, nextHex);
                }
            }
            yield return(null);
        }
        isMoving = false;
        StopCoroutine(MoveCharacter());
        yield break;
    }