How do you animate collection of game objects as a whole?

Hi guys, I’m trying to create fancy tetris. Mechanics are same, problem I have is that when line is completed I want whole line to behave as one object and shrink instead of just destroying. So line(s) start to getting shrinked until line disappears and only after that above tetrominos move down. Now I could easily animate separate tetrominos, but I’m not sure how to animate line as a whole, I mean whole line should act like one shape/object shrink to it’s center and finally disappear, would appreciate any tips :slight_smile:

Supposing your “tetrominoes” are composed of several cubes, attach the cubes shaping your line to an empty gameObject whose position is the center of the line, then scale this empty:

[132971-tetrominoes.jpg*_|132971]

Following code not tested

private IEnumerator DestroyLine( Transform[] cubes )
{
     if( cubes.Length < 1 ) yield break ;

     Vector3 linePosition = cubes[0].position;
     for( int i = 1 ; i < cubes.Length )
        linePosition += cubes*.position ;*

GameObject line = new GameObject( “Line” );
line.transform.position = linePosition / cubes.Length ;

for( int i = 0 ; i < cubes.Length )
cubes*.SetParent( line.transform, true ) ; // worldPositionStays set to true*

float shrinkDuration = 1 ;
for( float t = 0 ; t < shrinkDuration ; t += Time.deltaTime )
{
line.transform.localScale = Vector3.Lerp( Vector3.one, Vector3.zero, t / shrinkDuration );
yield return null ;
}

Destroy( line ) ;
}
_*