現在、ターンベースのタイプのゲームを行っていますが、選択した敵の位置にプレーヤーを移動させる方法がわかりません。マウスボタンで選択した別のゲームオブジェクトにゲームオブジェクトを移動させますか?
これは、敵の位置を持つプレイヤースクリプトです。
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