Unity Space Shooter – Chapter 17 – Extending

Add new asteroid types

  1. Start by duplicating (2x) the asteroid object(drag from prefab) to scene.

 

  1. Customize each one by replacing the model with the alternates.
  2. Adjust the colliders.
  3. Rename and save as new prefabs.

Change the GameController to spawn all three

Change

public GameObject hazard;

to

public GameObjects[] hazards;

 

Change the spawn to select a random one from the list.

Remember to go back to the GameController Object and add those prefabs to the hazards list.

 

Star Field

Drag and drop the prefab starfield into the scene

Set the Y to just above the background.

Optionally fiddle with the lifetime and speed constants.

 

Rolling Cloud

Duplicate the Background as a child of background

Use the transform too. and Use vertex snapping(v) to get them butted from end to end.

This gives you two whole pieces to run.  The image is built to be seamless.

Add a new c# backgroundScroller script.  Not the mathf.repeat.  This is the key.

 

 

Enemies

So much

Create empty “Enemy” placeholder object and fill it with the model and exhaust model.

add rigid body and collider, then adjust.

Add movement compoent and make the value -5.

Add the destroy by contact component.

Make it a Prefab

Add the prefab to the gamecontroller’s list of hazards.

Run it.

 

Evasive manuver

 

Unity Space Shooter – Chapter 14 – Score Inside and Outside

Inside

You’ve seen it before.  Add these publics to the the GameController.

Then Add the components on the screen, then drag and drop.

Include UpdateScore() in the Start routine.

Outside

Make a public addscore routine in game controller

In any routine that needs to add a score, get a reference to the GameController, then at the right time, call the new routine. ( the AddScore() routines above doesnt match below, but  you get the picture.)

 

 

Unity Space Shooter – Chapter 13 – Sounds

Music… Drag and drop the music to the GameController Object(play on awake, loop)

 

Drag and drop audio into the prefabs like explosion and you don’t have to program anything.

Then drag and drop the audio clip and confirm “play on awake” is checked.

That takes care of explosions. Now shooting.

Drag and drop the audio clip onto the player object.(no play on awake)