//初期値共通まとめ関数 private void InitStart() { psf = PlayerStateFlg.WAIT; pasf = PlayerAnimStateFlg.WAIT; mat.SetTexture("_MainTex", filmushi_normal); nowtime = 0.0f; deadtime = 0.0f; waitnowtime = 0.0f; touchtime = 0.0f; groundRotation = 0.0f; touchtimeflg = false; animwalkflg = false; animclearflg = false; animfurimukiflg = false; animjumpflg = false; animwaitflg = false; animwait2flg = false; animdieflg = false; switchwaitflg = true; tapflg = false; onetapflg = false; swipeflg = false; jumpflg = false; enemycolflg = false; playendflg = true; }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Enemy") { enemycolflg = true; playendflg = false; psf = PlayerStateFlg.WAIT; rb2d.Pause(); print("敵に当たった"); var _particle = Instantiate(hitParticle); _particle.transform.position = (Vector3)collision.transform.position + Vector3.back * 5; _particle.GetComponent <ParticleSystem>().Play(); } if (collision.gameObject.tag == "Goal") { animclearflg = true; playendflg = false; //PlayerStart(); psf = PlayerStateFlg.WAIT; print("ゴールに当たった"); tf.parent = null; ChangeButterfly(); tapEffectTransform.GetComponent <Renderer>().enabled = false; } /* * if (collision.gameObject.tag == "Leaf") * { * if (collision.GetComponent<Leaf>().GetFallFlag() && collision.transform.position.y > tf.position.y) * { * enemycolflg = true; * playendflg = false; * psf = PlayerStateFlg.WAIT; * print("落下足場に当たった"); * } * }*/ }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Enemy" && !animdieflg) { enemycolflg = true; playendflg = false; psf = PlayerStateFlg.WAIT; rb2d.Pause(); print("敵に当たった"); var _particle = Instantiate(hitParticle); _particle.transform.position = (Vector3)collision.contacts[0].point + Vector3.back * 5; _particle.GetComponent <ParticleSystem>().Play(); } //if (jumpflg&&(collision.gameObject.tag == "Branch" || collision.gameObject.tag == "Leaf" || collision.gameObject.tag=="RedBranch")) //{ // if (collision.contacts.Length == 1 && collision.contacts[0].normal.y>=0.5f && collision.contacts[0].normal.y<=0.99f) // { // var _work_pos = tf.position; //一旦Transformを退避 // var _work_rot = tf.rotation; // //斜面に合わせて傾ける // float _groundRotation = Mathf.Atan2(collision.contacts[0].normal.y, collision.contacts[0].normal.x) * Mathf.Rad2Deg - 90.0f; // tf.RotateAround(collision.contacts[0].point, Vector3.forward,_groundRotation); // Collider2D[] result = new Collider2D[2]; // //他の足場にも接触するようなら傾きを戻す // if (capsuleCollider.OverlapCollider(groundFilter, result) > 1) // { // tf.position = _work_pos; // tf.rotation = _work_rot; // } // //SetGroundRotation(_groundRotation); // } // Vector2 groundRotationNormal = Vector2.zero; // int cnt = 0; // foreach (var col in collision.contacts) // { // if (col.normal.y >= 0.5f) // { // LayerMask layer = LayerMask.GetMask("Branch"); // RaycastHit2D ray = Physics2D.Raycast(col.point, Vector2.down, 0.01f, layer); // if (ray.transform == null) // { // layer = LayerMask.GetMask("Leaf"); // ray = Physics2D.Raycast(col.point, Vector2.down, 0.01f, layer); // } // //ray = Physics2D.Raycast(col.point, Vector2.down,,LayerMask.NameToLayer("Branch")); // groundRotationNormal += ray.normal; // cnt++; // print(ray.transform.gameObject); // print(ray.normal); // } // } // groundRotationNormal /= (float)cnt; // float _rotation = Mathf.Rad2Deg * Mathf.Atan2(groundRotationNormal.y, groundRotationNormal.x) - 90; // SetGroundRotation(_rotation); //} }
//タップ、スワイプ検知処理 private void DetectionTapOld() { //タップをする if (Input.GetMouseButtonDown(0)) { //最初にタップされた座標を取得 changemousePos = Input.mousePosition; tapstartPos = Camera.main.ScreenToWorldPoint(changemousePos); tapstartget = new Vector2(tapstartPos.x, tapstartPos.y); //タップされたらカウントフラグをtrueにする touchtimeflg = true; } //タップされたらカウント開始 if (touchtimeflg == true) { touchtime += 1.0f; } //一定時間が過ぎると処理に入る if (touchtime >= touchendtime) { //カウントフラグをfalseにする touchtimeflg = false; //カウント経過後にタップされた座標を取得 changemousePos = Input.mousePosition; tapendPos = Camera.main.ScreenToWorldPoint(changemousePos); tapendget = new Vector2(tapendPos.x, tapendPos.y); //最初にタップされた座標とカウント後にタップされた座標がステージ内なら処理に入る。そしてゴールや死亡をしなければこの処理に入る if (Physics2D.Raycast(tapstartget, -Vector2.up, 0.001f, BackGround) && Physics2D.Raycast(tapendget, -Vector2.up, 0.001f, BackGround) && playendflg == true) { //最初にタップされたy座標よりカウント後のタップy座標の方が高ければジャンプ処理に入る if (tapstartPos.y < tapendPos.y) { swipeflg = true; animwalkflg = false; animfurimukiflg = false; touchtime = 0.0f; } //最初にタップされたy座標とカウント後のタップy座標が一緒であれば歩行処理に入る else if (tapstartPos.y == tapendPos.y) { tapflg = true; } //タップとプレイヤーの位置が一緒の場合は止まる if (tapflg == true && onetapflg == false && nowPos.x == tapendPos.x) { tapflg = false; onetapflg = true; touchtime = 0.0f; psf = PlayerStateFlg.WAIT; pasf = PlayerAnimStateFlg.WAIT; } //タップの位置がプレイヤーの位置より右にある場合は右に移動する else if (tapflg == true && onetapflg == false && nowPos.x < tapendPos.x) { tapflg = false; onetapflg = true; touchtime = 0.0f; psf = PlayerStateFlg.RIGHT; //プレイヤーが左を向いていた場合に右に向くように処理する if (nowscale.x < 0.0f) { pasf = PlayerAnimStateFlg.FURIMUKI; } else { pasf = PlayerAnimStateFlg.WAIK; } } //タップの位置がプレイヤーの位置より左にある場合は左に移動する else if (tapflg == true && onetapflg == false && nowPos.x > tapendPos.x) { psf = PlayerStateFlg.LEFT; tapflg = false; onetapflg = true; touchtime = 0.0f; //プレイヤーが右を向いていた場合に左に向くように処理する if (nowscale.x > 0.0f) { pasf = PlayerAnimStateFlg.FURIMUKI; } else { pasf = PlayerAnimStateFlg.WAIK; } } //タップが一度押されている場合はプレイヤーは停止する else if (tapflg == true && onetapflg == true) { psf = PlayerStateFlg.WAIT; pasf = PlayerAnimStateFlg.WAIT; touchtime = 0.0f; onetapflg = false; tapflg = false; } } } }
private void DetectionTapOld2() { //タッチ取得 if (Input.GetMouseButtonDown(0)) { //タッチ座標取得 Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //ステージ背景の中かつクリップ上ではない場所をクリックした時検知開始 if (stageCollider.OverlapPoint(mousePos) && !clipCollider.OverlapPoint(mousePos)) { touchtimeflg = true; tapstartPos = mousePos; } } //タッチ中フラグ if (touchtimeflg) { touchtime += Time.deltaTime; //時間超過でタップ判定を消す if (touchtime >= touchendtime) { touchtime = 0.0f; touchtimeflg = false; return; } else { //現在のタッチ座標取得 Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //タッチ位置より一定以上↑へスワイプした時ジャンプする if (mousePos.y > tapstartPos.y + swipeJudgeDistance) { swipeflg = true; animwalkflg = false; animfurimukiflg = false; touchtime = 0.0f; touchtimeflg = false; } //タッチ位置と近い位置で指が離れた時タップしたと判定する else if (Input.GetMouseButtonUp(0) && Vector2.Distance(tapstartPos, mousePos) < swipeJudgeDistance) { touchtime = 0.0f; touchtimeflg = false; //タップ時処理 //既にタップ位置へ移動中なら移動を中止する if (onetapflg) { onetapflg = false; psf = PlayerStateFlg.WAIT; pasf = PlayerAnimStateFlg.WAIT; tapEffectTransform.GetComponent <Renderer>().enabled = false; } //タップ位置がプレイヤーより右なら右へ移動する else if (tf.position.x < mousePos.x) { onetapflg = true; tapEffectTransform.GetComponent <Renderer>().enabled = true; tapEffectTransform.position = mousePos; tapEffectTransform.Translate(Vector3.back * 5); psf = PlayerStateFlg.RIGHT; //プレイヤーが左を向いていた場合に右に向くように処理する if (nowscale.x < 0.0f) { pasf = PlayerAnimStateFlg.FURIMUKI; } else { pasf = PlayerAnimStateFlg.WAIK; } } //タップ位置がプレイヤーより左なら左へ移動する else { onetapflg = true; tapEffectTransform.GetComponent <Renderer>().enabled = true; tapEffectTransform.position = mousePos; tapEffectTransform.Translate(Vector3.back * 5); psf = PlayerStateFlg.LEFT; //プレイヤーが右を向いていた場合に左に向くように処理する if (nowscale.x > 0.0f) { pasf = PlayerAnimStateFlg.FURIMUKI; } else { pasf = PlayerAnimStateFlg.WAIK; } } } } } }
private void DetectionTapOld3() { if (Input.GetMouseButtonDown(0)) { //タッチ座標取得 Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //ステージ背景の中かつクリップ上ではない場所をクリックした時検知開始 if (stageCollider.OverlapPoint(mousePos) && !clipCollider.OverlapPoint(mousePos)) { touchtimeflg = true; } } if (touchtimeflg) { Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); inputPosBuffer.Add(mousePos); Vector2 judgePos = new Vector2(); if (inputPosBuffer.Count < 10) { judgePos = inputPosBuffer[0]; } else { judgePos = inputPosBuffer[inputPosBuffer.Count - 10]; } //タッチ位置より一定以上↑へスワイプした時ジャンプする if (mousePos.y > judgePos.y + swipeJudgeDistance) { swipeflg = true; animwalkflg = false; animfurimukiflg = false; inputPosBuffer.Clear(); } //タップ位置がプレイヤーより右なら右へ移動する if (tf.position.x < mousePos.x - 0.1f) { onetapflg = true; tapEffectTransform.GetComponent <Renderer>().enabled = true; tapEffectTransform.position = mousePos; tapEffectTransform.Translate(Vector3.back * 5); psf = PlayerStateFlg.RIGHT; //プレイヤーが左を向いていた場合に右に向くように処理する if (nowscale.x < 0.0f) { pasf = PlayerAnimStateFlg.FURIMUKI; } else { pasf = PlayerAnimStateFlg.WAIK; } } //タップ位置がプレイヤーより左なら左へ移動する else if (tf.position.x > mousePos.x + 0.1f) { onetapflg = true; tapEffectTransform.GetComponent <Renderer>().enabled = true; tapEffectTransform.position = mousePos; tapEffectTransform.Translate(Vector3.back * 5); psf = PlayerStateFlg.LEFT; //プレイヤーが右を向いていた場合に左に向くように処理する if (nowscale.x > 0.0f) { pasf = PlayerAnimStateFlg.FURIMUKI; } else { pasf = PlayerAnimStateFlg.WAIK; } } } if (Input.GetMouseButtonUp(0)) { onetapflg = false; psf = PlayerStateFlg.WAIT; pasf = PlayerAnimStateFlg.WAIT; tapEffectTransform.GetComponent <Renderer>().enabled = false; touchtimeflg = false; inputPosBuffer.Clear(); } }
//移動用入力検知 private void DetectionTap() { //死んでたりたら止める if (animdieflg) { psf = PlayerStateFlg.WAIT; pasf = PlayerAnimStateFlg.WAIT; tapEffectTransform.GetComponent <Renderer>().enabled = false; touchtimeflg = false; inputPosBuffer.Clear(); return; } if (Input.GetMouseButtonDown(0)) { //タッチ座標取得 Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //ステージ背景の中かつクリップ上ではない場所をクリックした時検知開始 if (stageCollider.OverlapPoint(mousePos) && !clipCollider.OverlapPoint(mousePos)) { tapstartPos = mousePos; //タッチしたらマーカー表示 tapEffectTransform.GetComponent <Renderer>().enabled = true; tapEffectTransform.position = mousePos; tapEffectTransform.Translate(Vector3.back * 5); touchtimeflg = true; } } if (touchtimeflg) { Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //現在のタッチ座標をバッファへ格納 inputPosBuffer.Add(mousePos); Vector2 judgePos = new Vector2(); //バッファが大きくなりすぎないように古すぎるものは削除 if (inputPosBuffer.Count > 10) { inputPosBuffer.RemoveAt(0); } //ジャンプのための座標比較用 judgePos = inputPosBuffer[0]; //以前のフレームより一定以上↑へスワイプした時ジャンプ中でなければジャンプする if (mousePos.y > judgePos.y + swipeJudgeDistance && !animjumpflg) { swipeflg = true; animwalkflg = false; animfurimukiflg = false; inputPosBuffer.Clear(); } //タッチ座標が開始位置より一定以上右なら右へ移動する if (tapstartPos.x < mousePos.x - 0.1f) { //開始位置との距離によってスピードを変える if (mousePos.x - tapstartPos.x > maxSpeedDistance) { speed = retentionspeed; } else { speed = retentionspeed * (mousePos.x - tapstartPos.x) / maxSpeedDistance; } tapEffectTransform.localEulerAngles = Vector3.forward * 90; psf = PlayerStateFlg.RIGHT; //プレイヤーが左を向いていた場合に右に向くように処理する if (nowscale.x < 0.0f) { pasf = PlayerAnimStateFlg.FURIMUKI; } else { pasf = PlayerAnimStateFlg.WAIK; } } //タッチ座標が開始位置より一定以上左なら左へ移動する else if (tapstartPos.x > mousePos.x + 0.1f) { //開始位置との距離によってスピードを変える if (tapstartPos.x - mousePos.x > maxSpeedDistance) { speed = retentionspeed; } else { speed = retentionspeed * (tapstartPos.x - mousePos.x) / maxSpeedDistance; } tapEffectTransform.localEulerAngles = Vector3.back * 90; psf = PlayerStateFlg.LEFT; //プレイヤーが右を向いていた場合に左に向くように処理する if (nowscale.x > 0.0f) { pasf = PlayerAnimStateFlg.FURIMUKI; } else { pasf = PlayerAnimStateFlg.WAIK; } } //タッチ位置から動いてなければ止まる else { psf = PlayerStateFlg.WAIT; pasf = PlayerAnimStateFlg.WAIT; tapEffectTransform.localEulerAngles = Vector3.zero; } //離したら止まる if (Input.GetMouseButtonUp(0)) { psf = PlayerStateFlg.WAIT; pasf = PlayerAnimStateFlg.WAIT; tapEffectTransform.GetComponent <Renderer>().enabled = false; touchtimeflg = false; inputPosBuffer.Clear(); } } }