###前提・実現したいこと
unity および C# 初心者です。 今、unityでテトリスを作っているのですが、下記のコードで、deletefullrowの中で何列消えたかを出しているのですが、 下記のコードの下のほうにわかりやすく##で目印を置いたのですが、その部分に至ったらオーディオを流すということをしたいです。どなたか初心者でもわかりやすく説明してくれる方はいませんか?
###該当のソースコード
C#
1using UnityEngine; 2using System.Collections; 3 4public class Grid : MonoBehaviour { 5 public static int attackOneLine = 0; 6 public static int attackTwoLine = 1; 7 public static int attackThreeLine = 2; 8 public static int attackTetris = 4; 9 public static int attackTSpinOneLine = 2; 10 public static int attackTSpinTwoLine = 4; 11 public static int attackTSpinThreeLine = 6; 12 public static bool backToBack = false; 13 public static int numberOfThisTurn = 0; 14 public static bool tSpin = false; 15 public static int nowAtack = 0; 16 static Grid instance; 17 public AudioClip rensaOne; 18 public AudioClip rensaTwo; 19 public AudioClip rensaThree; 20 public AudioClip rensaFour; 21 public AudioClip rensaFive; 22 public AudioClip rensaSix; 23 public AudioClip rensaSeven; 24 public AudioClip rensTetris; 25 private AudioSource audioSource; 26 27 28 29 30 31 // The Grid itself 32 public static int w = 10; 33 public static int h = 25; 34 public static Transform[,] grid = new Transform[w, h]; 35 36 public static Grid Instance 37 { 38 get 39 { 40 //インスタンスがなければインスタンスを生成 Awakeより先にこのプロパティが呼ばれる可能性があるのでここでもチェックとnullであればインスタンス化します。 41 if (instance == null) instance = (Grid)FindObjectOfType(typeof(Grid)); 42 43 return instance; 44 } 45 } 46 47 void Awake() 48 { 49 //インスタンスがなければインスタンス化 50 if (instance == null) instance = (Grid)this; 51 //すでにインスタンスが存在すれば自身を破棄 インスタンスは1つでいいので重複対策です。 52 else if (Instance != this) Destroy(this); 53 } 54 public static Vector2 roundVec2(Vector2 v) { 55 return new Vector2(Mathf.Round(v.x), 56 Mathf.Round(v.y)); 57 58 59 } 60 61 62 63 public static bool insideBorder(Vector2 pos) { 64 return ((int)pos.x >= 0 && 65 (int)pos.x < w && 66 (int)pos.y >= 0); 67 } 68 public static void deleteRow(int y) { 69 for (int x = 0; x < w; ++x) { 70 Destroy(grid[x, y].gameObject); 71 grid[x, y] = null; 72 } 73 } 74 75 public static void decreaseRow(int y) { 76 for (int x = 0; x < w; ++x) { 77 if (grid[x, y] != null) { 78 // Move one towards bottom 79 grid[x, y-1] = grid[x, y]; 80 grid[x, y] = null; 81 82 // Update Block position 83 grid[x, y-1].position += new Vector3(0, -1, 0); 84 } 85 } 86 } 87 88 public static void decreaseRowsAbove(int y) { 89 for (int i = y; i < h; ++i) 90 decreaseRow(i); 91 } 92 93 public static bool isRowFull(int y) { 94 for (int x = 0; x < w; ++x) 95 if (grid[x, y] == null) 96 { 97 return false; 98 } 99 100 numberOfThisTurn++; 101 102 return true; 103 } 104 105 public static void deleteFullRows() { 106 for (int y = 0; y < h; ++y) { 107 if (isRowFull(y)) 108 { 109 110 111 112 113 deleteRow(y); 114 decreaseRowsAbove(y+1); 115 --y; 116 } 117 } 118 if (numberOfThisTurn == 0) 119 { 120 nowAtack = numberOfThisTurn; 121 } 122 if (backToBack != true) 123 { 124 if (tSpin == true) 125 { 126 if (numberOfThisTurn == 1) 127 { 128 nowAtack = attackTSpinOneLine; 129 } 130 else if (numberOfThisTurn == 2) 131 { 132 nowAtack = attackTSpinTwoLine; 133 } 134 else if (numberOfThisTurn == 3) 135 { 136 nowAtack = attackTSpinThreeLine; 137 } 138 } 139 else 140 { 141 if (numberOfThisTurn == 1) 142 { 143 nowAtack = attackOneLine; 144 } 145 else if (numberOfThisTurn == 2) 146 { 147 nowAtack = attackTwoLine; 148 } 149 else if (numberOfThisTurn == 3) 150 { 151 nowAtack = attackThreeLine; 152 } 153 else if (numberOfThisTurn == 4) 154 { 155 nowAtack = attackTetris; 156 157######ここでオーディオを流せるようにしたい。 158 159 160 161 162 } 163 164 } 165 } 166 167 if (backToBack == true) 168 { 169 if (tSpin == true) 170 { 171 if (numberOfThisTurn == 1) 172 { 173 nowAtack = attackTSpinOneLine; 174 nowAtack++; 175 } 176 else if (numberOfThisTurn == 2) 177 { 178 nowAtack = attackTSpinTwoLine; 179 nowAtack++; 180 } 181 else if (numberOfThisTurn == 3) 182 { 183 nowAtack = attackTSpinThreeLine; 184 185 nowAtack++; 186 nowAtack++; 187 } 188 } 189 else 190 { 191 if (numberOfThisTurn == 1) 192 { 193 nowAtack = attackOneLine; 194 } 195 else if (numberOfThisTurn == 2) 196 { 197 nowAtack = attackTwoLine; 198 } 199 else if (numberOfThisTurn == 3) 200 { 201 nowAtack = attackThreeLine; 202 } 203 else if (numberOfThisTurn == 4) 204 { 205 nowAtack = attackTetris; 206 nowAtack++; 207 } 208 209 } 210 } 211 Debug.Log(nowAtack); 212 213 214 } 215 216 217 218 219 // Use this for initialization 220 void Start () { 221 audioSource = GetComponent<AudioSource>(); 222 223 } 224 225 // Update is called once per frame 226 void Update () { 227 228 } 229}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。