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

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

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

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

Q&A

0回答

758閲覧

【Unity C#】順番に画像を表示したい

oniku_tabetai

総合スコア1

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

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

0グッド

0クリップ

投稿2020/06/06 12:20

編集2020/06/06 12:31

unityでシューティングゲームを作成しております。

スコアがある一定を超えたらキャラクターをゲットできる仕組みにしたく
合計で3対のキャラクターをスコア10,20,30でゲットできるようにしたいと考えております。

スコアの表示シーンでスコアを超えた場合は画像の挿入を行い、
もし30まで一気にスコアが達した場合は画像1(スコア10のキャラの画像),2(スコア20のキャラの画像),3(スコア30のキャラの画像),の順番でキャラクターの画像を差し込もうと考えております。

画像の表示回数は保存をしているので、もし1回スコア10に達した際にはその画像は出ないように設定をしております。

条件的に、
①スコア10での画像1のみ表示
②スコア20で画像1,2の表示
③スコア20でスコア10は一度クリアし、その際の保存は別で行っているので画像2のみの表示
④スコア30で画像1,2,3の表示
⑤スコア30で画像2,3の表示(スコア10は一度超えている)
⑥スコア30で画像3の表示(スコア20までは一度超えている)

このような条件分岐になると考え、下記のコードを実装しました。

画面をクリックした際に画像が切り替わるように設定をしたいのですが、下記のスクリプトですとスコア30だった場合、画像1が出た後に他のactiveになってレイヤーで下になっている画像2.3も同時に消えてしまいます。

どなたかアドバイスをいただけますと幸いです。

C#

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using UnityEngine.SceneManagement; 6using System; 7#if UNITY_IOS 8using UnityEngine.iOS; 9#endif 10 11public class EndManager : MonoBehaviour 12{ 13 14 int charaget1; 15 int charaget2; 16 int charaget3; 17 [SerializeField] 18 GameObject chara1, chara2, chara3; 19 20 public bool chara1on, chara2on, chara3on; 21 22void Start() 23{ 24 charaget1 = PlayerPrefs.GetInt("charaget1", 0); 25 charaget2 = PlayerPrefs.GetInt("charaget2", 0); 26 charaget3 = PlayerPrefs.GetInt("charaget3", 0); 27 28 29 if(GameManager.score > 10) 30 { 31 charaget1++; 32 PlayerPrefs.SetInt("charaget1", charaget1); 33 if (charaget1==1) 34 { 35 PlayerPrefs.SetInt(ShopSceneManager.chNames[2], 1); 36 Invoke("OnChara1", 1.5f); 37 38 } 39 40 } 41 42 if (GameManager.score > 20) 43 { 44 charaget1++; 45 charaget2++; 46 PlayerPrefs.SetInt("charaget1", charaget1); 47 PlayerPrefs.SetInt("charaget1", charaget2); 48 if (charaget1==1 &&charaget2 == 1) 49 { 50 PlayerPrefs.SetInt(ShopSceneManager.chNames[2], 1); 51 PlayerPrefs.SetInt(ShopSceneManager.chNames[5], 1); 52 Invoke("OnChara1", 1.5f); 53 Invoke("OnChara2", 1.5f); 54 55 } 56 else if (charaget1 > 1&& charaget2 == 1) 57 { 58 PlayerPrefs.SetInt(ShopSceneManager.chNames[5], 1); 59 Invoke("OnChara2", 1.5f); 60 61 } 62 63 } 64 65 if (GameManager.score > 30) 66 { 67 charaget1++; 68 charaget2++; 69 charaget3++; 70 PlayerPrefs.SetInt("charaget1", charaget1); 71 PlayerPrefs.SetInt("charaget1", charaget2); 72 PlayerPrefs.SetInt("charaget1", charaget3); 73 74 if (charaget1 == 1 && charaget2 == 1 && charaget3 == 1) 75 { 76 PlayerPrefs.SetInt(ShopSceneManager.chNames[2], 1); 77 PlayerPrefs.SetInt(ShopSceneManager.chNames[5], 1); 78 PlayerPrefs.SetInt(ShopSceneManager.chNames[8], 1); 79 Invoke("OnChara1", 1.5f); 80 Invoke("OnChara2", 1.5f); 81 Invoke("OnChara3", 1.5f); 82 83 } 84 else if (charaget1 > 1 && charaget2 == 1 && charaget3 == 1) 85 { 86 PlayerPrefs.SetInt(ShopSceneManager.chNames[5], 1); 87 PlayerPrefs.SetInt(ShopSceneManager.chNames[8], 1); 88 Invoke("OnChara2", 1.5f); 89 Invoke("OnChara3", 1.5f); 90 91 } 92 else if (charaget1 > 1 && charaget2 > 1 && charaget3 == 1) 93 { 94 PlayerPrefs.SetInt(ShopSceneManager.chNames[8], 1); 95 Invoke("OnChara3", 1.5f); 96 97 } 98 99} 100 101 102 void Update() 103 { 104 if (chara1on && chara2on && chara3on) 105 { 106 chara1.SetActive(true); 107 108 109 if (Input.GetMouseButton(0)) 110 { 111 chara1on = false; 112 chara1.SetActive(false); 113 114 115 } 116 117 118 } 119 120 121 if (chara1on && !chara2on && !chara3on) 122 { 123 chara1.SetActive(true); 124 125 126 if (Input.GetMouseButton(0)) 127 { 128 chara1on = false; 129 130 } 131 132 133 } 134 135 136 137 138 else if (!chara1on && chara2on && chara3on) 139 { 140 chara2.SetActive(true); 141 142 if (Input.GetMouseButton(0)) 143 { 144 chara2on = false; 145 chara2.SetActive(false); 146 147 148 } 149 150 } 151 else if (!chara1on && chara2on && !chara3on) 152 { 153 chara2.SetActive(true); 154 155 if (Input.GetMouseButton(0)) 156 { 157 chara2on = false; 158 chara2.SetActive(false); 159 160 161 162 } 163 164 } 165 else if (!chara1on && !chara2on && chara3on) 166 { 167 chara3.SetActive(true); 168 169 if (Input.GetMouseButton(0)) 170 { 171 chara3on = false; 172 173 chara3.SetActive(false); 174 175 176 } 177 } 178 179 180 181 } 182 183 184 185 public void OnChara1() 186 { 187 188 chara1on = true; 189 190 191 } 192 public void OnChara2() 193 { 194 195 chara2on = true; 196 197 198 } 199 public void OnChara3() 200 { 201 202 chara3on = true; 203 204 205 } 206} 207

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

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

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

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

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

sakura_hana

2020/06/08 01:47

「画像1が出た後に他のactiveになってレイヤーで下になっている画像2.3も同時に消えてしまいます。」の意味がわかりません。 また、条件の②と③が矛盾しているのと、⑤・⑥の意味がよく分かりません(画像1が表示されるのかどうか)。 大分複雑なので「スコアが幾つだとどの画像が表示されるか」ではなく「画像1が表示されるのはどのスコアの時か」と考えた方が楽かもしれません。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問