我目前正在制作一种基于回合的游戏类型,但是我仍然不知道如何将玩家移动到所选择的敌人位置。让一个gameobject移动到另一个被鼠标点击选中的gameobject?
这是玩家脚本与敌人的位置。
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());
}
}
玩家可以移动到怪物1的位置,但怪物2的脚本不起作用。即使我点击了怪物2,玩家仍然朝着怪物1的方向前进。
这是我放置在敌人脚本上的鼠标点击代码。
// Update is called once per frame
void Update() {
void OnMouseDown()
{
Debug.Log(gameObject.name);
BattleFlow.selectedEnemy = gameObject.name;
}
else子句正在检查与if子句完全相同的密钥。当然,它永远不会被执行。 – Milster