質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

1回答

438閲覧

PCビルドしたら実機と変わる

退会済みユーザー

退会済みユーザー

総合スコア0

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2020/01/16 10:01

編集2022/01/12 10:55

###現状
車を避けていくゲームを制作していて完成したのでビルドしてアプリケーション開いてみるとゲームは始めれるのですが当たり判定はあるがゲームオーバーにもならずにスコアも上がらない

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 }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2020/01/16 10:33

あなたのコードにバグがあるから、ということになろうかと。 で、それだけでどーせーとw
退会済みユーザー

退会済みユーザー

2020/01/16 10:42

ですよね笑 帰宅したらコードあげます笑
Y0241-N

2020/01/17 06:02

実機といってもプラットフォームは様々あります、またUnityのバージョンや開発環境(PCのOS)などの情報も必要です。 まずはそれらの情報を追記してください。
退会済みユーザー

退会済みユーザー

2020/01/17 06:08

ありがとうございます いろいろスクリプト変えた結果ビルドしても正常に動く様になりました
Y0241-N

2020/01/17 08:40

よかったですね。 ではそのことを自己回答の上、この質問をクローズしておいてください。
guest

回答1

0

スクリプトの設計し直しで解決しました

投稿2020/01/17 08:56

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問