//
    void FixedUpdate()
    {
        //左右に移動させない main_cameraを動かさない
        if (!gameClear)
        {
            playerMove();

            //現在のカメラの位置から8低くした位置を下回った時
            if (gameObject.transform.position.y < Camera.main.transform.position.y - 8)
            {
                //LifeScriptのGameOverメソッドを実行する
                lifeScript.GameOver();
            }
        }
        // ゲームクリア時
        else
        {
            //クリアーテキストを表示
            clearText.enabled = true;
            //アニメーションは走り
            anim.SetBool("Dash", true);
            //右に進み続ける
            rigidbody_2d.velocity = new Vector2(speed, rigidbody_2d.velocity.y);
            //5秒後にタイトル画面へ戻るCallTitleメソッドを呼び出す
            Invoke("CallTitle", 5);
        }
    }
Exemple #2
0
    void Update()
    {
        //Linecastでユニティちゃんの足元に地面があるか判定
        isGrounded = Physics2D.Linecast(
            transform.position + transform.up * 1,
            transform.position - transform.up * 0.07f,
            groundLayer);
        //スペースキーを押し、
        if (Input.GetKeyDown("space"))
        {
            //着地していた時、
            if (isGrounded)
            {
                //Dashアニメーションを止めて、Jumpアニメーションを実行
                anim.SetBool("Dash", false);
                anim.SetTrigger("Jump");
                //着地判定をfalse
                isGrounded = false;
                //AddForceにて上方向へ力を加える
                rigidbody2D.AddForce(Vector2.up * jumpPower);
            }
        }
        //上下への移動速度を取得
        float velY = rigidbody2D.velocity.y;
        //移動速度が0.1より大きければ上昇
        bool isJumping = velY > 0.1f ? true:false;
        //移動速度が-0.1より小さければ下降
        bool isFalling = velY < -0.1f ? true:false;

        //結果をアニメータービューの変数へ反映する
        anim.SetBool("isJumping", isJumping);
        anim.SetBool("isFalling", isFalling);

        if (Input.GetKeyDown("z"))
        {
            anim.SetTrigger("Shot");
            Instantiate(bullet, transform.position + new Vector3(0f, 1.2f, 0f), transform.rotation);
        }
        if (gameObject.transform.position.y < Camera.main.transform.position.y - 8)
        {
            lifescript.GameOver();
        }
    }