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)

 

 

Unity Space Shooter – Chapter 10 – asteroid collision

Asteroid continued  – Now add pretty explosions including the fatal player collision.

Expand on the collision script…

To make it blow up by spawning an explosion

Using tag to identify Player,  and have it blow up

 

 

Then reuse the Movement code by dragging and dropping it onto the Asteroid. then setting speed in negative direction.

Unity Space Shooter – Chapter 9 – Asteroid prefab(rotation)

Create Opponent

  1. Setup a template asteroid object (chapter 8)
  2. Save it as a Prefab (chapter 9)
  3. Expand programming so it happens in groups

 

Part 1

Create Placeholder Game Object called Asteroid(reset transforms, change z above player object so we can see them relative to each other)

Drag and drop the model for an asteroid into it(reset transforms)

[ This continues the pattern of Parent object holds the program, child is what to render.]

Back at “Asteroid” Add rigidbody(no gravity, no angular drag) , Capsule collider and scale it.

Back at “asteroid” add a new c# program with “start” routine so we can set a random tumble for the object when it starts

That takes care of start. But what about hit?  New Object for that that has a collider trigger like the boundary(but enter not exit variety)

So on the same “asteroid” object, create another c# script called DestroyByContact

Debug.Log(other.name);

 

Unity Space Shooter – Chapter 8 – boundary collider

Create a boundary around the game play area so the shots can be removed from play after they fall off the field.

 

  1. Create a box larger than the play area
    1. Create Cube
    2. Scale it
    3. Make sure it has a box collider
    4. isTrigger is checked
    5. Remove the Cube(mesh filter)
    6. Remove the mesh renderer.
  2. Create script(to handle the trigger) DestroyByBoundary
  3. Edit and add the OnTriggerExit routine.  When triggered, it will destroy the other object.
  4. Easy

Unity Space Shooter – Chapter 7 – fire laser shot from player

Shooting shots.

Create an game object called “shotSpawn” as a child of our player.  This will become the origin for the shot when started, but we need a way to communicate between the object and the c# program, so we make a couple helpers

Edit “PlayerController”

Object:

Positon:

Rotation:

We need a way to fill those in.

In the c#

public GameObject shot; // what gets shot

public Transform shotSpawn; // the object to use to get the shot

In Unity

Make an empty game object called ShotSpawn as a child of the Player object. Adjust it to the tip of the nose.  This is where the initial location comes from.

Drag the bullet from the Prefabs into the new “shot” reference

Drag the ShotSpawn into the new shotSpawn reference

 

That is the setup.

 

Now to shoot.

Instantiate the shot when button is clicked (but include a pause) so we dont fire one every frame

 

Unity Space Shooter – Chapter 6 – create laser prefab

Shot fire Object

A lot going on.

We create a game object called “Bolt” and add a child object(quad) called VFX.  We make this two parts so we can separate the logic from rendering.

  1.  Game Object  called “Bolt” This will be our primary shot object. The bolt object has movement(rigid body) and collision detection(capsule collider)
  2. Child Game object called VFX(quad) (transform rotate 90 to see)
  3. Create a material
    1. Go to material folder
    2. Create new new material and name it fx_bolt_orange
    3. Use the “select” picker to attach the texture of the bolt
    4. Select shading as mobile/particles/additive
  4. Drag and drop new material onto Quad
  5. Setup collision
    1. Remove “mesh collider” from VFX object(there by default)
    2. Go to Bolt and add component physics/capsule collider
      1. Adjust the size
      2. Change Direction to z-axis
    3. Select “isTrigger” checkbox to make it a “trigger collider”
    4. Attach a new Script called “Mover”

    5. see the new public “speed” set that on the Bolt object(20 is ok)
    6.  Test by playing.
    7. Move it to Prefab
    8. Test by playing and drag and drop as often as you want.

 

Create new Material

fx_bolt_orange