Example #1
0
    void Start()
    {
        assetsManager    = FindObjectOfType <AssetsManager>();
        stageManager     = FindObjectOfType <StageManager>();
        cameraController = FindObjectOfType <CameraController>();
        rigid2D          = GetComponent <Rigidbody2D>();
        animator         = GetComponent <Animator>();
        attackArea       = FindObjectOfType <AttackArea>();
        moveLeft         = false;
        moveRight        = false;

        // 攻撃コライダを無効化
        attackArea.GetComponent <BoxCollider2D>().enabled = false;
        // 開始位置を保持
        initPosition = transform.position;
        // 死亡フラグを初期値に戻す
        died = false;
    }
Example #2
0
    void Update()
    {
        // ジャンプ処理
        if (Input.GetKeyDown(KeyCode.Space))
        {
            JumpButtonDown();
        }

        // 移動処理
        float speedx = Mathf.Abs(rigid2D.velocity.x);

        if (Input.GetKey(KeyCode.RightArrow) || moveRight)
        {
            // 右キー押下時
            if (transform.localScale.x < 0)
            {
                transform.localScale = new Vector3(-1 * transform.localScale.x, transform.localScale.y, 1);
            }
            rigid2D.AddForce(transform.right * walkForce);
            if (speedx < maxWalkSpeed)
            {
                rigid2D.AddForce(transform.right * walkForce);
            }
        }
        else if (Input.GetKey(KeyCode.LeftArrow) || moveLeft)
        {
            // 左キー押下時
            if (transform.localScale.x > 0)
            {
                transform.localScale = new Vector3(-1 * transform.localScale.x, transform.localScale.y, 1);
            }
            rigid2D.AddForce(transform.right * walkForce * -1);
            if (speedx < maxWalkSpeed)
            {
                rigid2D.AddForce(transform.right * walkForce * -1);
            }
        }

        // アニメーションの速度変更
        if (animator.GetCurrentAnimatorStateInfo(0).IsName(GameUtil.Const.ANIMETION_NAME_ATTACK))
        {
            // 攻撃中の場合スピード固定
            animator.speed = 3.5f;
            // 攻撃コライダを有効化
            attackArea.GetComponent <BoxCollider2D>().enabled            = true;
            attackArea.GetComponent <BoxCollider2D>().transform.position = transform.position;
            attackArea.GetComponent <BoxCollider2D>().transform.Translate(scale * 5, 0, 0);
        }
        else
        {
            // 攻撃中でない場合、移動速度に合わせる
            animator.speed = speedx / 2.0f;
            // 攻撃コライダを無効化
            attackArea.GetComponent <BoxCollider2D>().enabled = false;
        }

        // 落下した場合の処理
        if (transform.position.y < -10)
        {
            PlayerDead(0.5f);
        }
    }