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