
前提・実現したいこと
現在、サッカーをモチーフにしたクリッカーゲームを作っている者です。
クリックによるスコアの上昇などの機能は出来たのですが、アイテムショップの機能を追加することに苦戦しています。
Scriptについてもですが、そもそもの構成要素などにも不安を抱えています。
まずは実装までの考え方を「文字で」理解したいです。
最終地点は、ゲーム内通貨を消費してアイテムを購入するシステムの構築です。
まさに以下の画像のようなイメージです。
現状
UIのButton機能を使って配置・装飾(画像の挿入など)止まり
試したこと
右も左も分からない状態でどこへ向かえば良いのかわからず、とにかく書店やサイトを探しましたが類似例はほとんど見つかりませんでした。
### 仕様
・アイテムは大きく分けて2種類(1クリック当たりの生産を増やす物、自動生成ぺースを高める物)
・ゲーム内で生産したゲーム内通貨を消費してアイテムを購入
・レベルマックス、アンロックはグレーアウト
・アイテム購入の際は「購入しますか?はいorいいえ」のようなシーンは設けず、クリック後すぐに購入・実装
見つけた参考になりそうなページ
理想は以下のようなものですが、用語を置き換えるだけで成立するのでしょうか...?
http://yasuaki-ohama.hatenablog.com/entry/2015/05/16/092032
http://yasuaki-ohama.hatenablog.com/entry/2016/07/06/235528
C#
1 2using System.Collections; 3using Syollections.Generic; 4using UnityEngine; 5using UnityEngine.UI; 6using System; 7 8public class GameManager : MonoBehaviour { 9 10 //定数定義 11 private const int MAX_ORB = 5000; //オーブ最大数 12 private const int RESPAWN_TIME = 15; //オーブが発生する秒数 13 private const int MAX_LEVEL = 5; //最大キーパーレベル 14 15 //データセーブ用キー 16 private const string KEY_SCORE = "SCORE"; //スコア 17 private const string KEY_LEVEL = "LEVEL"; //レベル 18 private const string KEY_ORB = "ORB"; //オーブ数 19 private const string KEY_TIME = "TIME"; //時間 20 21 //オブジェクト参照 22 public GameObject orbPrefab; //オーブプレハブ 23 public GameObject trophyPrefab; //トロフィープレハブ 24 public GameObject canvasGame; //ゲームキャンバス 25 public GameObject textScore; //スコアテキスト 26 public GameObject imageKeeper; //キーパー 27 public float clickrate = 0.5f; 28 public GameObject ball; 29 30 //メンバ変数 31 private int score = 0; //現在のスコア 32 private int nextScore = 400; //レベルアップまでに必要なスコア 33 34 private int currentOrb = 0; //現在のオーブ数 35 36 private int keeperLevel = 0; //キーパーのレベル 37 38 private DateTime lastDateTime; //前回オーブを生成した瞬間 39 40 private int[] nextScoreTable = new int[] { 100,200,300,400,500 }; //レベルアップ値 41 42 private int numOfOrb; //まとめて生成するオーブの数 43 44 // Use this for initialization 45 void Start () { 46 47 //データ削除メソッド 48 //PlayerPrefs.DeleteAll(); 49 50 //初期設定 51 score = PlayerPrefs.GetInt(KEY_SCORE, 0); 52 keeperLevel = PlayerPrefs.GetInt(KEY_LEVEL, 0); 53 54 nextScore = nextScoreTable[keeperLevel]; 55 imageKeeper.GetComponent<KeeperManager>().SetKeeperPicture(keeperLevel); 56 imageKeeper.GetComponent<KeeperManager>().SetKeeperScale(score, nextScore); 57 58 RefreshScoreText(); 59 60 } 61 62 // Update is called once per frame 63 void Update () { 64 //まとめて生成するオーブがあれば生成 65 while (numOfOrb > 0) 66 { 67 Invoke("CreateNewOrb",0.1f*numOfOrb); 68 numOfOrb--; 69 } 70 } 71 72 //バックグラウンドへの移行時と復帰時(アプリ起動時も含む)に呼び出される 73 74 private void OnApplicationPause(bool pauseStatus) 75 { 76 if (pauseStatus) 77 { 78 //アプリがバックグラウンドへ移行 79 } 80 else 81 { 82 //バックグラウンドから復帰 83 //時間の復元 84 string time = PlayerPrefs.GetString(KEY_TIME, ""); 85 if (time == "") 86 { 87 lastDateTime = DateTime.UtcNow; 88 } 89 else 90 { 91 long temp = Convert.ToInt64(time); 92 lastDateTime = DateTime.FromBinary(temp); 93 } 94 95 numOfOrb = 0; 96 //時間によるオーブ自動生成 97 TimeSpan timeSpan = DateTime.UtcNow - lastDateTime; 98 if (timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME)) 99 { 100 while (timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME)) 101 { 102 if (numOfOrb < MAX_ORB) 103 { 104 numOfOrb++; 105 } 106 timeSpan -= TimeSpan.FromSeconds(RESPAWN_TIME); 107 } 108 } 109 } 110 } 111 112 //新しいオーブの生成 113 public void CreateNewOrb() 114 { 115 lastDateTime = DateTime.UtcNow; 116 if (currentOrb >= MAX_ORB) 117 { 118 return; 119 } 120 CreateOrb(); 121 currentOrb++; 122 123 SaveGameData(); 124 } 125 126 //オーブ生成 127 public void CreateOrb() 128 { 129 GameObject orb = (GameObject)Instantiate(orbPrefab); 130 orb.transform.SetParent(canvasGame.transform, false); 131 orb.transform.localPosition = new Vector3( 132 UnityEngine.Random.Range (-100.0f, 100.0f), 133 UnityEngine.Random.Range (-300.0f, -450.0f), 134 0f); 135 136 orb.GetComponent<OrbManager>().Flyorb(); 137 138 //ボールアニメーション 139 StartCoroutine("ClickAnim");//"ClickAnim"のコルーチンを呼ぶ. 140 141 } 142 143 144 145 //オーブ入手 146 public void GetOrb() 147 { 148 score += 1; 149 //キーパー画像切り替えメソッド挿入予定 150 151 //レベルアップ値を超えないように制限 152 if (score > nextScore) 153 { 154 score = nextScore; 155 } 156 157 KeeperLevelUp(); 158 RefreshScoreText(); 159 imageKeeper.GetComponent<KeeperManager>().SetKeeperScale(score, nextScore); 160 SaveGameData(); 161 162 163 164 } 165 166 //スコアテキスト更新 167 void RefreshScoreText() 168 { 169 textScore.GetComponent<Text>().text = 170 score + "GOAL"; 171 } 172 173 //キーパーのレベル管理 174 void KeeperLevelUp() 175 { 176 if (score >= nextScore) 177 { 178 if (keeperLevel < MAX_LEVEL) 179 { 180 keeperLevel++; 181 score = 0; 182 183 KeeperLevelUpEffect(); 184 185 nextScore = nextScoreTable[keeperLevel]; 186 imageKeeper.GetComponent<KeeperManager>().SetKeeperPicture(keeperLevel); 187 } 188 } 189 } 190 191 //レベルアップ時の演出 192 void KeeperLevelUpEffect() 193 { 194 GameObject trophy = (GameObject)Instantiate(trophyPrefab); 195 trophy.transform.SetParent(canvasGame.transform, false); 196 trophy.transform.SetSiblingIndex(5); 197 198 Destroy(trophy, 0.5f); 199 } 200 201 //ゲームデータをセーブ 202 void SaveGameData() 203 { 204 PlayerPrefs.SetInt(KEY_SCORE, score); 205 PlayerPrefs.SetInt(KEY_LEVEL,keeperLevel); 206 PlayerPrefs.SetInt(KEY_ORB,currentOrb); 207 PlayerPrefs.SetString(KEY_TIME,lastDateTime.ToBinary().ToString()); 208 209 210 PlayerPrefs.Save(); 211 }
有識者の方、どうぞよろしくお願い致します。


回答1件
あなたの回答
tips
プレビュー