コード例 #1
0
    public override void OnEndTurn()
    {
        // 移動方向を決定する
        GameObject player = SearchPlayer();
        int        x      = 0;
        int        y      = 0;

        if (player) // プレイヤーが見つかった場合はその方向に移動する
        {
            if (Mathf.Abs(player.transform.position.x - this.transform.position.x) > float.Epsilon)
            {
                x = player.transform.position.x > this.transform.position.x ? 1 : -1;
            }

            if (Mathf.Abs(player.transform.position.y - this.transform.position.y) > float.Epsilon)
            {
                y = player.transform.position.y > this.transform.position.y ? 1 : -1;
            }
        }
        else // プレイヤーが見つからない場合はランダムに移動する
        {
            x = Random.Range(-1, 2);
            y = Random.Range(-1, 2);
        }

        m_gridMove.Move(x, y, m_moveTime);
    }
コード例 #2
0
    void Update()
    {
        if (m_gridMove.IsMoving)    // 動いている最中は何もしない
        {
            return;
        }

        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");

        if (h != 0 || v != 0)
        {
            // 移動可能ならば移動して、ターンを進める
            if (m_gridMove.Move((int)h, (int)v, m_moveTime))
            {
                TurnManagerDelegate.EndTurn();
            }
        }
    }