Spawn two connected blocks Horizontal or Vertical Randomly?

I want to spawn two connected blocks VERTICAL OR HORIZONTAL RANDOMLY at the top of the screen.
And i want to down them like tetris game when i click mouse button.?

136024-screenshot-1.jpg

My blocks code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
 [RequireComponent(typeof(MeshRenderer), typeof(MeshFilter))]
 public class Block : MonoBehaviour {
     public Color blockColor;
     
     private void Awake() {
         GetComponent<MeshRenderer>().material.color = blockColor;
     }
 
     private void Update() {
         transform.position += Vector3.down * Time.deltaTime;
     }
 }

And BlocksManager

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 public class BlocksManager : MonoBehaviour {
 
     // farklı renklere sahip blokları alma
     public List<GameObject> blockPrefabs = new List<GameObject>();
 
     // blokların spawnlanma frekansları
    // public float spawnFrequency = 2f;
 
     // blokların farklı renklere zorlama
     public bool forceDifferentColors = false;
 
     // blokların spawnlanma pozisyonları
     public Vector3 spawnPosition;
     private GameObject fallingBlocks1;
     private GameObject fallingBlocks2;
     
     private float timer;
 
     // random numara üretiyor
     private System.Random prng;
 
     
     
     private void Start() 
     {
             if (blockPrefabs.Count == 0) {
             throw new System.Exception("No block types found in the blocks list.");
     	}
//     	Vector2 originalVector = new Vector2(4.3f,1.3f);
//     	Vector2 newVector = Vectorf.Round(originalVector);
//     	Debug.Log(newVector.ToString());
     	prng = new System.Random();
     }

     private void Update() {
         timer += Time.deltaTime;
 
         if (Input.GetKeyDown(KeyCode.Space)) {
 
             /*
             Zamanlayıcıyı 0'a ayarlamak yerine, 
			zamanlayıcıyı ortaya çıkma sıklığına göre düşürüyoruz 
			çünkü bu şekilde spawnlama periyodunu daha güzel düzenleriz.
              */
            // timer -= spawnFrequency;
             CreateNewBlocks();
         }
     }      	
 
 	private void CreateNewBlocks() {
 
         // 0 sabit ama blocksPrefabs.Count sayı olarak değişir.
         int randomBlock1 = prng.Next(0, blockPrefabs.Count);
         int randomBlock2 = prng.Next(0, blockPrefabs.Count);
 
         
         // eğer 2.bloğun farklı renk olmasını zorlamak istiyorsam 
         // ve 1 den fazla blok prefabi varsa bu formül
         if (forceDifferentColors && blockPrefabs.Count > 1) {
             while (randomBlock1 == randomBlock2) {
                 randomBlock2 = prng.Next(0, blockPrefabs.Count);
             }
         }
        	//I want to spawn two connected blocks VERTICAL OR HORIZONTAL RANDOMLY
         Vector3 position1 = spawnPosition + Vector3.left / 2f;
         Vector3 position2 = spawnPosition + Vector3.right / 2f;
         
         
//         Vector3 position3 = spawnPosition += Vector3.up / 2f;
//         Vector3 position4 = spawnPosition += Vector3.down / 2f;
         
                  
        Instantiate(blockPrefabs[randomBlock1], position1, Quaternion.identity,transform);
        Instantiate(blockPrefabs[randomBlock2], position2, Quaternion.identity,transform);
     }
}
  1. use prng to get a 0 or 1
  2. If 0:

let everything be as it is

  1. if 1:

switch Vector3.left in spawn position to Vector3.up and Vector3.right to Vector3.down

  1. profit

Also I recommend learning more simple contents of programming if you don’t understand what that piece of code actualy do.

Thanks for helping … Do you recommend any course or learning for beginners?
And also i took an error. Can you help ?

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 public class BlocksManager : MonoBehaviour {
 
     // farklı renklere sahip blokları alma
     public List<GameObject> blockPrefabs = new List<GameObject>();
 
    // Spawner m_spawner;
     
     // blokların spawnlanma frekansları
    // public float spawnFrequency = 2f;
 
     // blokların farklı renklere zorlama
     public bool forceDifferentColors = false;
 
     // blokların spawnlanma pozisyonları
     public Vector3 spawnPosition;
          
     public float timer;
 
     // random numara üretiyor
     public System.Random prng;
 
     
     
 	public void Start() 
     {
             if (blockPrefabs.Count == 0) {
             throw new System.Exception("No block types found in the blocks list.");
     	}

//	   	Vector2 originalVector = new Vector2(4.3f,1.3f);
//  	Vector2 newVector = Vectorf.Round(originalVector);
//	  	Debug.Log(newVector.ToString());
//		//m_spawner = GameObject.FindObjectOfType<GameObject>();
		
//		if(m_spawner){
//			m_spawner.transform.position = Vectorf.Round(m_spawner.transform.position);
//		}
		//new int someValue = Random.Range(0,2);
		var rand = random.Range(1,3);
		prng = new System.Random();
     	
     	
     	
     }

 		public void Update() {
         timer += Time.deltaTime;
 
         if (Input.GetKeyDown(KeyCode.Space)) {
 
             /*
             Zamanlayıcıyı 0'a ayarlamak yerine, 
			zamanlayıcıyı ortaya çıkma sıklığına göre düşürüyoruz 
			çünkü bu şekilde spawnlama periyodunu daha güzel düzenleriz.
              */
            // timer -= spawnFrequency;
            if(rand==1){
            	CreateNewBlocks1();}
            else if (rand==2){
            	CreateNewBlocks2();
            	}
	         

    	   }      	
 
         public void CreateNewBlocks1() {
 
         // 0 sabit ama blocksPrefabs.Count sayı olarak değişir.
         int randomBlock1 = prng.Next(0, blockPrefabs.Count);
         int randomBlock2 = prng.Next(0, blockPrefabs.Count);
 
         
         // eğer 2.bloğun farklı renk olmasını zorlamak istiyorsam 
         // ve 1 den fazla blok prefabi varsa bu formül
         if (forceDifferentColors && blockPrefabs.Count > 1) {
             while (randomBlock1 == randomBlock2) {
                 randomBlock2 = prng.Next(0, blockPrefabs.Count);
             }
         }
        
         Vector3 position1 = spawnPosition + Vector3.left / 2f;
         Vector3 position2 = spawnPosition + Vector3.right / 2f;
         
                           
        Instantiate(blockPrefabs[randomBlock1], position1, Quaternion.identity,transform);
        Instantiate(blockPrefabs[randomBlock2], position2, Quaternion.identity,transform);
     }
 
 		 public void CreateNewBlocks2() {
 
         // 0 sabit ama blocksPrefabs.Count sayı olarak değişir.
         int randomBlock1 = prng.Next(0, blockPrefabs.Count);
         int randomBlock2 = prng.Next(0, blockPrefabs.Count);
 
         
         // eğer 2.bloğun farklı renk olmasını zorlamak istiyorsam 
         // ve 1 den fazla blok prefabi varsa bu formül
         if (forceDifferentColors && blockPrefabs.Count > 1) {
             while (randomBlock1 == randomBlock2) {
                 randomBlock2 = prng.Next(0, blockPrefabs.Count);
             }
         }
         
          	Vector3 position3 = spawnPosition += Vector3.up / 2f;
	        Vector3 position4 = spawnPosition += Vector3.down / 2f;
                         
        Instantiate(blockPrefabs[randomBlock1], position1, Quaternion.identity,transform);
        Instantiate(blockPrefabs[randomBlock2], position2, Quaternion.identity,transform);
     }
}
   
 }