O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required