Survival Shooter – Chapeter 3 – Camera

Change the camera to follow…

Go to MainCamera

Change X,Y,Z => 1, 15, -22

Rotation -> 30,0,0

Projection -> othographic with size 4.5

Background Color -> Black

 

Script time…

Create a script called CameraFollow and edit.


using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour {
public Transform target;
public float smoothing = 5f;

private Vector3 offset;

void Start(){
offset = transform.position - target.position;

}
void FixedUpdate(){
Vector3 transformCamPos = target.position + offset;
transform.position = Vector3.Lerp (transform.position, transformCamPos, smoothing * Time.deltaTime);
}
}

<span style="line-height: 1.5;">

Make sure it compiles and drag/drop it into the camera object.

 

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)

 

 

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);