0
0

More than 1 year has passed since last update.

【テトリス作成⑤】数値を丸めるクラスについて深掘る

Last updated at Posted at 2022-11-15

こちらを元に解説しています。
https://qiita.com/hanatan079/items/3675855784e14acda119

★★★★★随時更新★★★★★
2022.11.22追記
2022.11.30追記
2022.12/7追記
★★★★★★★★★★★★★★★

Rounding.cs
        public class Rounding : MonoBehaviour →
        public static class Rounding 

{
    ①public static Vector2 Round(Vector2 i)
    {
        ②return new Vector2(Mathf.Round(i.x), Mathf.Round(i.y));
    }

    ①public static Vector3 Round(Vector3 i)
    {
        ②return new Vector3(Mathf.Round(i.x), Mathf.Round(i.y));
    }
}

丸める処理は何回か行う為、クリプト作成して使いまわせるようにする
①Vector2、Vector3のiを丸める
xyを返す
変数iに近いxy(z)のを生成する。
  
MonoBehaviourについて
https://qiita.com/hanatan079/items/b42e499ec2cd9d134fb0
Round関数について
https://qiita.com/hanatan079/items/a109b40b0e159779590c

(見本)Board.cs

    //④ブロックが枠内にあるのか判定する関数を呼ぶ関数
        public bool CheckPosition(Block block)
        {
            foreach (Transform item in block.transform)
            {
                //変更
                Vector2 pos = Rounding.Round(item.position);
                //new Vector2(Mathf.Round(item.position.x),Mathf.Round(item.position.y));

                if(!BoardOutCheck((int)pos.x, (int)pos.y))
                {
                    return false;
                }
                //⑥移動先が空いているのか確認する関数を呼ぶ
                if (BlockCheck((int)pos.x, (int)pos.y,block))
                {
                    return false;
                }
            }
            return true;
        }



 Vector2 pos = new Vector2(Mathf.Round(item.position.x),Mathf.Round(item.position.y));
//こっちに変更
Vector2 pos = Rounding.Round(item.position);

丸める関数(ファイル)の呼び出し

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0