Im currently making a turn based type of game however im stuck figuring out how to move the player to the position of the enemy that was chosen.
This is the player script with the positions of the enemies.
void Update()
{
if ((Input.GetKeyDown("1")) && (BattleFlow.playerTurn == 1)) // attack monster 1
{
BattleFlow.currentDamage = 40;
GetComponent<Animator>().SetTrigger("PlayerMelee");
GetComponent<Transform>().position = new Vector2(-4.78f, 3.68f);
StartCoroutine(playerAttack());
}
else if ((Input.GetKeyDown("1")) && (BattleFlow.playerTurn == 1)) // attack monster 2
{
GetComponent<Animator>().SetTrigger("PlayerMelee");
GetComponent<Transform>().position = new Vector2(-4.45f, 1.77f);
StartCoroutine(playerAttack2());
}
}
The player can move to the location of monster 1 however the script for monster 2 doesn’t work. The player still goes towards the direction of monster 1 even though I clicked monster 2.
This is the code for the mouse click which I placed on the enemy script.
// Update is called once per frame
void Update () {
void OnMouseDown()
{
Debug.Log(gameObject.name);
BattleFlow.selectedEnemy = gameObject.name;
}
}
Can any help me with the scripting? Much appreciated.