//トリガーモードでほかのオブジェクトと接触した場合の処理 private void OnTriggerEnter(Collider other) { //障害物に衝突した場合 if (other.gameObject.tag == "CarTag" || other.gameObject.tag == "TrafficConeTag") { Debug.Log("d"); this.isEnd = true; this.eMotion = enumMotion.WaitFirstMotionAfterEnd; WriteUITextResult("Game Over."); } //ゴール地点に到達した場合 if (other.gameObject.tag == "GoalTag") { Debug.Log("g"); this.isEnd = true; this.eMotion = enumMotion.WaitFirstMotionAfterGoal; WriteUITextResult("Clear!!"); } //コインに衝突した場合 if (other.gameObject.tag == "CoinTag") { Debug.Log("c"); //スコアを加算 this.score += 10; //ScoreText獲得した点数を表示 if (this.scoreText) { this.scoreText.GetComponent <Text>().text = "Score " + this.score + "pt"; } //パーティクルを再生 ParticleSystem psystem = this.gameObject.GetComponent <ParticleSystem>() as ParticleSystem; if (psystem != null) { psystem.Play(); } //接触したコインのオブジェクトを破棄 Destroy(other.gameObject); // (this.gameObject.GetComponent<ParticleSystem>() as ParticleSystem).Stop(); } }
// Update is called once per frame void Update() { //発展課題:ユニティちゃんの位置に応じてアイテムを動的に生成しましょう //アイテムを生成する関数を呼び出し if (mItemGenScript != null) { mItemGenScript.UpdateItem(this.gameObject.transform.position.z); } //ゲーム終了ならUnityちゃんの動きを減衰する if (this.isEnd && eMotion != enumMotion.MotionLoopAfterEnd) { this.forwardForce *= this.coefficient; this.turnForce *= this.coefficient; this.upForce *= this.coefficient; this.myAnimator.speed *= this.coefficient; //Unityちゃんの動きが十分に減衰したら、次のモーションに映る if (this.myAnimator.speed <= 0.01f) { switch (eMotion) { case enumMotion.WaitFirstMotionAfterEnd: //ゲームオーバの場合 eMotion = enumMotion.FirstMotionAfterEnd; break; case enumMotion.WaitFirstMotionAfterGoal: //ゲームクリアの場合 eMotion = enumMotion.FirstMotionAfterGoal; break; default: break; } } } //ゲームが終了したら息切れしたポーズを行う if (eMotion == enumMotion.FirstMotionAfterEnd) { Debug.Log("eMotion 1stEnd"); this.myAnimator.speed = 1.0f; //アニメーションのspeedを1に戻す // this.myAnimator.Play("REFLESH00"); //ゲームオーバのモーション eMotion = enumMotion.MotionLoopAfterEnd; this.gameObject.AddComponent <GameOverMotion>(); DestroyMySelf(); } //ゴールしてゲームが終了しポーズをループする if (eMotion == enumMotion.FirstMotionAfterGoal) { Debug.Log("eMotion 1st Goal"); this.myAnimator.speed = 1.0f; //アニメーションのspeedを1に戻す // this.myAnimator.Play("WAIT04"); //ゲームクリアのモーション eMotion = enumMotion.MotionLoopAfterEnd; this.gameObject.AddComponent <GameClearMotion>(); DestroyMySelf(); } //unityちゃんに前方向の力を加える(追加) if (canMove) { this.myRigidbody.AddForce(this.transform.forward * this.forwardForce); } //Unityちゃんを矢印キーまたはボタンに応じて左右に移動させる if ((Input.GetKey(KeyCode.LeftArrow) || this.isLButtonDown) && (-this.movableRange < this.transform.position.x)) { this.myRigidbody.AddForce(-this.transform.right * this.turnForce); } if ((Input.GetKey(KeyCode.RightArrow) || this.isRButtonDown) && (this.movableRange > this.transform.position.x)) { this.myRigidbody.AddForce(this.transform.right * this.turnForce); } //Jumpステートの場合はJumpにfalseをセットする (追加) if (this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("Jump")) { this.myAnimator.SetBool("Jump", false); } if (Input.GetKey(KeyCode.Space) && this.transform.position.y < 0.5f) { this.myAnimator.SetBool("Jump", true); this.myRigidbody.AddForce(this.transform.up * this.upForce); } }