###内容
テトリスを製作していて、削除時に点滅させるスプリクトを作ったがうまく
点滅してくれません。
どういったプログラムを書けばいいんでしょうか?
###ソースコード
using System.Collections; using System.Collections.Generic; using System.ComponentModel; using UnityEngine; using UnityEngine.UI; public class controller : MonoBehaviour { public float falltimer = 1f; public float timecounter; public float waittimer; public bool readymove = true; public static bool readyhold = true; public static bool firsthold = true; public static bool alrblock = false; public static bool gameovercontroll; public static int WIDTH = 10; public static int HIGHT = 20; private static Transform[,] grid = new Transform[WIDTH, HIGHT]; public Vector3 rotationPoint; // Start is called before the first frame update void Start() { gameovercontroll = false; } // Update is called once per frame void Update() { if (readymove) { move(); } hold(); spell(); } void move() { //ブロックの移動 if (Input.GetKey(KeyCode.A) && Time.time - waittimer >= 0.05) { transform.position += new Vector3(-1, 0, 0); if (!movecontroll()) { transform.position -= new Vector3(-1, 0, 0); } waittimer = Time.time; } else if (Input.GetKey(KeyCode.D) && Time.time - waittimer >= 0.05) { transform.position += new Vector3(1, 0, 0); if (!movecontroll()) { transform.position -= new Vector3(1, 0, 0); } waittimer = Time.time; } else if (Input.GetKey(KeyCode.S) || Time.time - timecounter >= falltimer) { transform.position += new Vector3(0, -1, 0); if (!movecontroll()) { transform.position -= new Vector3(0, -1, 0); addgrid(); checkline(); readyhold = true; this.enabled = false; if(!gameovercontroll) { FindObjectOfType<spawn>().spawnblock(); } } timecounter = Time.time; } if (Input.GetKey(KeyCode.W)&&Time.time - waittimer >=0.1) { transform.RotateAround(transform.TransformPoint(rotationPoint), new Vector3(0, 0, 1), 90); if(!movecontroll()) { transform.RotateAround(transform.TransformPoint(rotationPoint), new Vector3(0, 0, 1), -90); } waittimer = Time.time; } } //ブロックの制御 bool movecontroll() { foreach (Transform children in transform) { int roundX = Mathf.RoundToInt(children.transform.position.x); int roundY = Mathf.RoundToInt(children.transform.position.y); if (roundX < 0 || roundX >= WIDTH || roundY < 0 || roundY >= HIGHT) { return false; } if(grid[roundX,roundY]!=null) { return false; } } return true; } //ブロックが重なるようにする void addgrid() { foreach (Transform children in transform) { int roundX = Mathf.RoundToInt(children.transform.position.x); int roundY = Mathf.RoundToInt(children.transform.position.y); grid[roundX, roundY] = children; if (roundY >= HIGHT - 1) { gameovercontroll = true; // GameOverメソッドを呼び出す FindObjectOfType<GameManagement>().gameover(); } } } // ラインがあるか?確認 public void checkline() { for (int i = HIGHT - 1; i >= 0; i--) { if (HasLine(i)) { DeleteLine(i); RowDown(i); } } } // 列がそろっているか?確認 bool HasLine(int i) { for (int j = 0; j < WIDTH; j++) { if (grid[j, i] == null) return false; } return true; } // ラインを消す void DeleteLine(int i) { for(int ct=0;ct<4;ct++) { for (int j = 0; j < WIDTH; j++) { grid[j, i].gameObject.SetActive(false); } System.Threading.Thread.Sleep(500); for (int j = 0; j < WIDTH; j++) { grid[j, i].gameObject.SetActive(true); } System.Threading.Thread.Sleep(500); } for (int j = 0; j < WIDTH; j++) { Destroy(grid[j, i].gameObject); grid[j, i] = null; } FindObjectOfType<GameManagement>().AddScore(); } // 列を下げる public void RowDown(int i) { for (int y = i; y < HIGHT; y++) { for (int j = 0; j < WIDTH; j++) { if (grid[j, y] != null) { grid[j, y - 1] = grid[j, y]; grid[j, y] = null; grid[j, y - 1].transform.position -= new Vector3(0, 1, 0); } } } } void hold() { if(Input.GetKey(KeyCode.Q)&&readyhold) { if(readymove) { transform.position = new Vector3(15, 17, 0); readymove = false; } else { transform.position = new Vector3(5, 18, 0); readymove = true; } if(firsthold) { FindObjectOfType<spawn>().spawnblock(); firsthold = false; readyhold = false; } if(readyhold&&alrblock) { readyhold = false; alrblock = false; } else if(readyhold) { alrblock = true; } } } void spell() { if(Input.GetKey(KeyCode.X)) { for (int j = 0; j < WIDTH; j++) { if(grid[j,2]!= null) { Destroy(grid[j, 2].gameObject); grid[j, 2] = null; } } RowDown(2); } } }
###問題の箇所
for(int ct=0;ct<4;ct++) { for (int j = 0; j < WIDTH; j++) { grid[j, i].gameObject.SetActive(false); } System.Threading.Thread.Sleep(500); for (int j = 0; j < WIDTH; j++) { grid[j, i].gameObject.SetActive(true); } System.Threading.Thread.Sleep(500); }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/27 03:03