I need help with my 3D tetris game.

I need help in trying to register subblocks of the tetraminoes in the tetris game I am making. It is only registering one middle block where the pivot is rather than all four blocks of the tetraminoe , I have tried changing the pivot from centre to pivot and nothing is working , i think it has to do with the code but I am still new to programming and would appreciate any help.
below is the code for the individual tetraminoe.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TetrisBlock : MonoBehaviour
{
    GameLogic gameLogic;
    bool movable = true;
    float timer = 0f;
    public GameObject rig;

    // Start is called before the first frame update
    void Start()
    {
        gameLogic = FindObjectOfType<GameLogic>();
    }

    void RegisterBlock()
    {
        foreach(Transform subBlock in rig.transform)
        {
            gameLogic.grid[Mathf.FloorToInt(subBlock.position.x),
                Mathf.FloorToInt(subBlock.position.y),
                Mathf.FloorToInt(subBlock.position.z)] = subBlock;
        }
    }

    bool CheckValid()
    {
        foreach(Transform subBlock in rig.transform)
        {
            if(subBlock.transform.position.z >= GameLogic.width ||
                subBlock.transform.position.x >= GameLogic.length ||
                subBlock.transform.position.x < 0 ||
                subBlock.transform.position.y < 0 ||
                subBlock.transform.position.z < 0 )
            {
                return false;
            }
            if (subBlock.position.y < GameLogic.height && gameLogic.grid
                [Mathf.FloorToInt(subBlock.position.x),
                Mathf.FloorToInt(subBlock.position.y),
                Mathf.FloorToInt(subBlock.position.z)] != null)
            {
                return false;
            }
        }
        return true;
    }

    // Update is called once per frame
    void Update()
    {
        if (movable)
        {
            //Updating the timer
            timer += 1 * Time.deltaTime;
            //Drop
            if (Input.GetKey(KeyCode.Space) && timer > GameLogic.quickFallTime)
            {
                gameObject.transform.position -= new Vector3(0, 1, 0);
                timer = 0;
                if (!CheckValid())
                {
                    movable = false;
                    gameObject.transform.position += new Vector3(0, 1, 0);
                    RegisterBlock();
                    gameLogic.SpawnBlock();
                }
            }
            else if (timer > GameLogic.fallTime)
            {
                gameObject.transform.position -= new Vector3(0, 1, 0);
                timer = 0;
                if (!CheckValid())
                {
                    movable = false;
                    gameObject.transform.position += new Vector3(0, 1, 0);
                    RegisterBlock();
                    gameLogic.SpawnBlock();
                }
            }

            //Sideways movement
            if (Input.GetKeyDown(KeyCode.A))
            {
                gameObject.transform.position += new Vector3(-1, 0, 0);
                if (!CheckValid())
                {
                    gameObject.transform.position -= new Vector3(-1, 0, 0);
                }
            }
            else if (Input.GetKeyDown(KeyCode.D))
            {
                gameObject.transform.position += new Vector3(1, 0, 0);
                if (!CheckValid())
                {
                    gameObject.transform.position -= new Vector3(1, 0, 0);
                }
            }
            else if (Input.GetKeyDown(KeyCode.W))
            {
                gameObject.transform.position += new Vector3(0, 0, 1);
                if (!CheckValid())
                {
                    gameObject.transform.position -= new Vector3(0, 0, 1);
                }
            }
            else if (Input.GetKeyDown(KeyCode.S))
            {
                gameObject.transform.position += new Vector3(0, 0, -1);
                if (!CheckValid())
                {
                    gameObject.transform.position -= new Vector3(0, 0, -1);
                }
            }

            //Rotation
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                rig.transform.eulerAngles -= new Vector3(0, 0, 90);
                if (!CheckValid())
                {
                    gameObject.transform.position += new Vector3(0, 0, 90);
                }
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                rig.transform.eulerAngles -= new Vector3(0, 90, 0);
                if (!CheckValid())
                {
                    gameObject.transform.position += new Vector3(0, 90, 0);
                }
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                rig.transform.eulerAngles -= new Vector3(90, 0, 0);
                if (!CheckValid())
                {
                    gameObject.transform.position += new Vector3(90, 0, 0);
                }
            }
        }
        return ;
    }
}

while the code for area the tetris block is about to move freely in is

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameLogic : MonoBehaviour
{
    public static float fallTime = 0.9f;
    public static float quickFallTime = 0.01f;
    public static int length = 10, width = 10, height = 20;
    public GameObject[] blocks;
    public Transform[,,] grid = new Transform[length, width, height];

    void Start()
    {
        SpawnBlock();
    }

    public void SpawnBlock()
    {
        float guess = Random.Range(0, 1f);
        guess *= blocks.Length;
        Instantiate(blocks[Mathf.FloorToInt(guess)]);
    }
}

Welcome to Debugging 101! Here’s how to get started on your journey:

You must find a way to get the information you need in order to reason about what the problem is.

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: https://discussions.unity.com/t/700551 or this answer for Android: https://discussions.unity.com/t/699654

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

https://discussions.unity.com/t/839300/3


If anyone want to help me dev my online 3d tetris version
then you are welcome.

Regards from Sweden

Awesome although the camera angle is tough to work with, mine will be orthorgraphic topdown , like those from this game
https://play.google.com/store/apps/details?id=com.kiarygames.tinyroom&hl=en with you being able to change the camera with something like a swipe or button.

any chance you can share the code for yours for me to see how you implemented your game.

https://github.com/jlivingstonsg/BlockOut

MagI