Time for action - fixing the fall

In The Break-Up, our falling objects were larger, and they fell through a smaller vertical range. Now that there's no ground to hit and the sky's the limit, we should tweak a few lines of code in our EnemyShip Script (formerly the FallingObject Script). Double-click the EnemyShip Script and roll up your sleeves:

  • Change:
    if(transform.position.y < 0)
    
  • to:
    if(transform.position.y < -4)
    

This allows the enemy ship to reposition itself when it moves off the bottom edge of the screen, instead of when it hits the non-existent ground plane at y:0.

  • Change:
    transform.position.y = 50;
    
  • to:
    transform.position.y = 71;
    

When the EnemyShip is repositioned, cranking up its y value will start it just above the top edge of the screen.

Get Unity 3D Game Development by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.