//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.