I am building a 2D RPG game. In the turn-based battle scene, after the player clicks the Start button, the hero will first be translated to the enemy’s position, wait for a while and and then be moved back to his original position. I have problem playing these three sequences of actions.
I have a function that is called when user clicks the start button:
void OnStartButtonClick() {
StartCoroutine(CharacterAttack());
}
IEnumerator CharacterAttack() {
// store the player's original position
Vector3 originalPosition = player.gameObject.transform.position;
// move player to enemy's position
yield return StartCoroutine( MoveCharacterToPoint(player.gameObject, enemy.gameObject.transform.position) );
yield return StartCoroutine( MoveCharacterToPoint(player.gameObject, originalPosition));
}
MoveCharacterToPoint is a function that does the fundamental translation.
However, the above code only moves the player to enemy’s position, but cannot move it back. How can I modify my code?