###現状
車を避けていくゲームを制作していて完成したのでビルドしてアプリケーション開いてみるとゲームは始めれるのですが当たり判定はあるがゲームオーバーにもならずにスコアも上がらない
Unityのpcでしてる分にはきちんとできるのですがビルドするとできなくなります
後なぜかすぐに(体感いつもの1/20)ビルド終わります
###実現したいこと
PCビルドでも正常にゲームができて欲しい
該当コード
unity
1gamemanagerコード 2 void Start() 3 { 4 //開始時にRedayステート開始 5 Ready(); 6 Player = GameObject.FindWithTag("Playercon"); 7 playcon = Player.GetComponent<PlayerCotroller>(); 8 Time.timeScale = 1; 9 PlayerPrefs.SetInt("NowScore", 0); 10 } 11 12 void LateUpdate() 13 { 14 //ステートごとにイベント監視 15 switch (state) 16 { 17 case State.Ready://タッチしたらゲームスタート 18 if (Input.GetButtonDown("Fire1")||Input.GetKeyDown("space")) GameStart(); 19 break; 20 case State.Play://車が破壊されたらゲームオーバー 21 if (playcon.IsDead()) GameOver(); 22 break; 23 case State.GameOver: 24 count += Time.deltaTime; 25 if (count >= 1.0f) 26 { 27 Time.timeScale = 0; 28 Title.gameObject.SetActive(true);//タイトルボタン表示 29 StateLabel.gameObject.SetActive(false); 30 scoreLabel.gameObject.SetActive(false); 31 coinLabel.gameObject.SetActive(false); 32 if (Input.GetKeyDown("space")) 33 { 34 //ゲームシーンを読み込み 35 SceneManager.LoadScene("Game"); 36 } 37 if (Input.GetKeyDown("right")||Input.GetKeyDown("left")) 38 { 39 //タイトルシーンを読み込み 40 SceneManager.LoadScene("Title"); 41 } 42 } 43 break; 44 } 45 } 46 47 // Update is called once per frame 48 void Update() 49 { 50 PlayerPrefs.SetInt("NowScore", score); 51 } 52 53 void Ready() 54 { 55 state = State.Ready; 56 //オブジェクトを無効にする 57 EnemyGenerator.SetActive(false); 58 CoinGenerator.SetActive(false); 59 //ラベル更新 60 scoreLabel.text = "Score : " + 0; 61 StateLabel.gameObject.SetActive(true); 62 StateLabel.text = "READY"; 63 coinLabel.text = "Coin : " + 0; 64 } 65 void GameStart() 66 { 67 state = State.Play; 68 //オブジェクトを有効にする 69 EnemyGenerator.SetActive(true); 70 CoinGenerator.SetActive(true); 71 //ラベル更新 72 StateLabel.gameObject.SetActive(false); 73 StateLabel.text = ""; 74 } 75 void GameOver() 76 { 77 state = State.GameOver; 78 //ラベル更新 79 StateLabel.gameObject.SetActive(true); 80 //オブジェクトを無効にする 81 EnemyGenerator.SetActive(false); 82 CoinGenerator.SetActive(false); 83 StateLabel.text = "GAMEOVER"; 84 //ハイスコアを更新 85 if (PlayerPrefs.GetInt("ScoreHighScore") < score) 86 { 87 PlayerPrefs.SetInt("ScoreHighScore", score); 88 } 89 PlayerPrefs.SetInt("Totalcoin", coin + PlayerPrefs.GetInt("Totalcoin")); 90 endscoreLabel.text = "Score : " + score; 91 endcoinLabel.text = "Coin : " + coin; 92 }
unity
1playercontrollerコード 2 public bool IsDead() 3 { 4 return isDead; 5 } 6 7 // Start is called before the first frame update 8 void Start() 9 { 10 controller = GetComponent<CharacterController>();//キャラコントローラー取得 11 } 12 13 // Update is called once per frame 14 void Update() 15 { 16 //死んでいたら動かせない 17 if (isDead) return; 18 19 //フリック入力(スマホ用) 20 Flick(); 21 //矢印入力(PC用) 22 if (Input.GetKeyDown("right")) MoveToRight(); 23 if (Input.GetKeyDown("left")) MoveToLeft(); 24 25 //X方向は目的のポジションまでの差分の割合で速度計算 26 float ratioX = (targetLane * LaneWidth - transform.position.x) / LaneWidth; 27 moveDirection.x = ratioX * speedX; 28 29 moveDirection.y -= gravity * Time.deltaTime;//重力加える 30 31 //移動実行 32 Vector3 gloabalDirection = transform.TransformDirection(moveDirection); 33 controller.Move(gloabalDirection * Time.deltaTime); 34 } 35 36 public void ReDead() 37 { 38 //ぶつかったらフラグを立てる 39 isDead = true; 40 } 41
unity
1playerdeadコード 2 GameObject Dead; 3 public GameObject explosion; 4 5 // Start is called before the first frame update 6 void Start() 7 { 8 //開始時にplayerを見つける 9 Dead = GameObject.FindWithTag("Playercon"); 10 } 11 12 // Update is called once per frame 13 void Update() 14 { 15 16 } 17 18 public void OnTriggerEnter(Collider other) 19 { 20 if (other.gameObject.CompareTag("Playercon")) 21 { 22 Dead.SendMessage("ReDead"); 23 } 24 Collider thiscol = GetComponent<Collider>(); 25 Vector3 hit = thiscol.ClosestPointOnBounds(other.transform.position); 26 if (other.gameObject.CompareTag("Playercon")) 27 { 28 GameObject go = Instantiate(explosion, hit, Quaternion.identity) as GameObject; 29 go.transform.parent = transform; 30 } 31 32 }