Esempio n. 1
0
    void Update()
    {
        //コストを取得する
        CostManager c = m_costMana.GetComponent <CostManager>();

        m_cost = c.Cost;

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

        plaPos = this.transform.position;
        Vector2 dir = AdjustInputDirection(h, v);   // 入力方向を4方向に変換(制限)する

        // オブジェクトを動かす
        //transform.Translate(m_walkSpeed * dir * Time.deltaTime);    // このやり方でもできるが、コライダーにめり込む
        m_rb.velocity = dir * m_walkSpeed;
        // 入力方向によって左右の向きを変える
        if (dir.x != 0)
        {
            m_sprite.flipX = (dir.x > 0);
        }

        //Animate(dir.x, dir.y);
        if (dir == Vector2.zero)
        {
            m_isWalking = false;
        }
        else
        {
            m_isWalking = true;
        }
        m_anim.SetBool("IsWalking", m_isWalking);
        m_anim.SetFloat("InputX", Mathf.Abs(dir.x));
        m_anim.SetFloat("InputY", dir.y);
        m_lastMovedDirection = dir;

        //Mapの情報を取得する
        MapGenerator t = m_mapGene.GetComponent <MapGenerator>();

        int[,] m = t.Map;
        //playerのポジションを四捨五入して兵器のポジションを決める
        weaPos.x = Mathf.RoundToInt(plaPos.x);
        weaPos.y = Mathf.RoundToInt(plaPos.y);
        //拠点以外のタイルの場合に
        if (m[weaPos.x, weaPos.y] != 5 && m[weaPos.x, weaPos.y] != 6)
        {
            //兵器コストがあるときに
            if (m_cost > 0)
            {
                //SpaceKeyを押されたとき兵器を置く
                if (Input.GetKeyDown("space"))
                {
                    audioSource.PlayOneShot(m_weaponSet);
                    weapon.WeaponInstance(weaPos);
                    //コストを減らす
                    m_cost -= m_weaponCost;
                    //CostManager c = m_costMana.GetComponent<CostManager>();
                    c.DecreaseCost();
                }
            }
        }
    }