Moving two connected object and match them with respect to colors?

Im trying a game for my School Project.

And I have 8 different block prefabs

Blocks script

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;
     }
 }

BlocksManager

using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEditor;
  
  public class BlocksManager : MonoBehaviour {
  
      // farklı renklere sahip blokları alma
      [Header("Blocks")]
      public List<GameObject> blockPrefabs = new List<GameObject>();

		 int nextBlock1;
		 int nextBlock2;

//      float fallSpeed = 1.0f;
		Transform fallingBlock1;
		Transform fallingBlock2;

      // public bool forceDifferentColors = false;
      
      
      
      [Header("SpawnPosition")]
      public Vector3 spawnPosition;    
      public float timer;

      public System.Random prng;

      private int RandomChance;
      
      
      [Header("Interface")]
       public Transform gameOver;
       public Transform next;


      public void Awake() {
      	
      	      	

        prng = new System.Random();
        
        RandomBlock();      
         
          
      }
 
          public void Update() {
          timer += Time.deltaTime;
          RandomChance = Random.Range(1,3); 
          if (Input.GetKeyDown(KeyCode.Space)) {
  

             // timer -= spawnFrequency;
 			CreateNewBlocks(); 
            }       
      }
  
      
      public void RandomBlock(){
 
      	
      		
      	if(RandomChance==1){
      	
		int randomBlock1 = prng.Next(0,blockPrefabs.Count);
		int randomBlock2 = prng.Next(0,blockPrefabs.Count);
		
		// Remove previous 'next block'
		
		foreach(Transform child in next){ GameObject.Destroy(child.gameObject);}

		// Add new block
		
		GameObject nextFallingBlock1 = Instantiate(blockPrefabs[randomBlock1], Vector3.zero,Quaternion.identity,next);
		GameObject nextFallingBlock2 = Instantiate(blockPrefabs[randomBlock2], Vector3.zero,Quaternion.identity,next);
		
		// Offset position
		
		nextFallingBlock1.transform.localPosition = new Vector3(0.5f, 0.0f, 0.0f)+ Vector3.left/2f;
		nextFallingBlock2.transform.localPosition = new Vector3(0.5f, 0.0f ,0.0f)+ Vector3.right/2f;
		
		nextBlock1 = randomBlock1;
		nextBlock2 = randomBlock2;
      	}
      	
      	else if(RandomChance==2){
      		
      	int randomBlock1 = prng.Next(0,blockPrefabs.Count);
		int randomBlock2 = prng.Next(0,blockPrefabs.Count);
		
		// Remove previous 'next block'
		
		foreach(Transform child in next){ GameObject.Destroy(child.gameObject);}
		
		// Add new block
		
		GameObject nextFallingBlock1 = Instantiate(blockPrefabs[randomBlock1], Vector3.zero,Quaternion.identity,next);
		GameObject nextFallingBlock2 = Instantiate(blockPrefabs[randomBlock2], Vector3.zero,Quaternion.identity,next);
		
		// Offset position
		
		nextFallingBlock1.transform.localPosition = new Vector3(0.5f, 0.0f, 0.0f)+ Vector3.up/2f;
		nextFallingBlock2.transform.localPosition = new Vector3(0.5f, 0.0f, 0.0f)+ Vector3.down/2f;
		
		nextBlock1 = randomBlock1;
		nextBlock2 = randomBlock2;
      		
      	}
      	
//      	if(!CheckValidPosition()){
//      		
//      		Destroy(
//      	}
		
      }
      
      
      
         private void CreateNewBlocks() {
      		
      	//ChanceOfDrop = Random.Range(1,3);
    	            	
            	if(RandomChance==1){
         
         Vector3 position1 = spawnPosition + Vector3.left / 2f;
         Vector3 position2 = spawnPosition + Vector3.right / 2f;
                            
         fallingBlock1=Instantiate(blockPrefabs[nextBlock1], position1, Quaternion.identity,transform.GetChild(1).transform).transform;
         fallingBlock2=Instantiate(blockPrefabs[nextBlock2], position2, Quaternion.identity,transform.GetChild(2).transform).transform;
         RandomBlock();
         
      	}
		 
            else if(RandomChance==2){
 

         Vector3 position3 = spawnPosition + Vector3.up / 2f;
	     Vector3 position4 = spawnPosition + Vector3.down / 2f;
                         
	     fallingBlock1=Instantiate(blockPrefabs[nextBlock1], position3, Quaternion.identity,transform.GetChild(1).transform).transform;
	     fallingBlock2=Instantiate(blockPrefabs[nextBlock2], position4, Quaternion.identity,transform.GetChild(2).transform).transform;
        RandomBlock();
      	}
  }
      
  }

I want to instanstiate two of them with connected at top of the screen.And i want to move them right,left or down together.And destroy them when the same colors are matched
But I couldn’t do it. Can you help me?


Ok:

block2.transform.parent = block1.transform; //block 2 is now the child of block 1

To rotate around the center point, which I think would be best. Use:

Vector2 direction = block2.transform.position - block1.transform.position; //get direction and length
Vector2 centrePoint = block1.transform.position + (direction * 0.5f); //Find mid point

RotateAround( centrePoint, Vector3.forward, 90 ); //this will rotate around the center point about the z axis 90 degrees, you can also make a smooth transition to 90 degrees if you multiply the last parameter by Time.deltaTime for example, which will do 90 degrees in 1 second, but you would have to setup a timer to know when to stop (timer starts at 0.0 and add Time.deltaTime after every time you apply the rotation and stop when the timer equals 1

Best way would be to use tags for comparison, give different tag to each game object, so the the gameobjects with same color should have the same tag, than you can compare tags rather than colors