How Can I Make a Moving Object with a trigger reaction ? [C#]

Hi

I’m a beginner on Unity and I want to make this

http://puu.sh/2hUPs

You can see that on the 1 situation, bloc A and B are continualy moving up and down,

when the player enter in the trigger those bloc move to be stick together,

and when you go out the trigger, they move to their initial place and go up and down like

the first image

how can I do this thing please

Thank you

Simple state machine.

//Incomplete script
public class Block : MonoBehaviour {
   public string state = "moving";

   void Update() {
      if( state == "moving" ) {
         //Do up and down movement
      }
      else {
         //Stick to something
      }
   }
}

Then, attach a script to the trigger that modifies the state of the Block when a player enter/exit the trigger.

public class TriggerZone : MonoBehavior {
   public Block a, b;

   void OnTriggerEnter( Collider other ) {
      if( other.gameObject.CompareTag("player") ) {
         a.state = "stick";
         b.state = "stick";
      }
   }

   void OnTriggerExit( Collider other ) {
      if( other.gameObject.CompareTag("player") ) {
         a.state = "moving";
         b.state = "moving";
      }
   }
}

This is very rudimentary. You will have to do some work to get it to be exactly what you show in the picture. By the way, you can press the picture icon or Ctrl+G to attach a photo to your question.