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 on 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.
Change:
transform.position.x = Random.Range(0, 60);
to:
transform.position.x = Random.Range(-11, 68);
This gives the EnemyShip a corrected horizontal range at which to spawn—somewhere between -11
and 68
along the X-axis. You can either delete or comment...