Time for action – give up the func

Let's get that function set up in the EnemyShip Script first. Double-click to open the EnemyShip Script, and get typing.

  1. Write this new function outside of and apart from the other functions in the script:
    function ResetPosition(){
      transform.position.y = 71;
      transform.position.x = Random.Range(-11, 68);
      transform.position.z = 0;
      rigidbody.velocity = Vector3.zero;
    }
    

    These are the very same repositioning lines we already have. You can even just type the shell of the function, and copy/paste those lines right in there. Either way, you need to go back and eradicate those lines from the Update function and replace them with a ResetPosition() function call.

  2. Erase these bolded lines:
     if(transform.position.y < -4) ...

Get Unity 4.x Game Development by Example Beginner's Guide 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.