Angular 2

nodejs is required (get to know npm)

command line is your friend.

Microsoft’s Visual Studio Code is pretty handy.

Typescript takes  javascript type structures, then compiles them

They say use webpack for distribution

Apps use model-view controllers. The controller is called a “component.” It ties a view(or portion of the whole view) to a tag.

tsconfig.json tells us what type of script to compile to – we use ES5, commonjs formats

app.component is the standard place to make the

Get Started with Angular 2 by Building a Simple Website

npm start

Component building:


  • Create your class
  • Import your dependencies
  • Decorate your class
  • Enhance with composition
  • Repeat for sub-components

RC4 into RC6

Consolidates components

angular cli install

$ npm install -g angular-cli
$ ng new {app-name} --routing
$ cd {app-name}
$ ng serve

Using angular cli commands

Build a base class with unit test:

$ ng generate class {my-class} --spec

Build a service(business logic in a service):

$ ng generate service {my-service}

Gen a component(like navbar, sidebar, main-1, main-2, etc)

ng generate component {my-component}


A ragged, jagged nail caused annoyance. As her teeth and tongue grappled with the sharp unevenness, her brows furrowed.

Reports all have a life of their own. All reports are meant to communicate. They direct and teach. They issue warnings and edicts. They are devoid of empathy, sympathy; unable to sing. And Janice had seen more than her fair share. Her work exposed her to countless reports, some that reoccur like crop reports and missile silo allocation. Others are one-offs meant to provide a glimpse into the eternal.

Who wanted these reports? Mostly tax collectors, sometimes accountants and Occasionally politicians when they wanted to provide the imitation of science while manipulating a segment of the population.

Janice was none of these. Her training in psychology led her to the edge of a career in the medical professions. A chance, short affair, with a sly professor taught her more than she ever wanted about the nature of human beings.

People were messy, complicated, but not in a Sunday afternoon jigsaw puzzle sort of way, more like tsunami. After she learned people were motivated by a mere hand full of ideas, mostly fear based, her passion waned.

Reports aren’t dumb. But this one didn’t make sense. Janice eyes scanned for patterns, flaws, anything to help her mind make sense of what she was seeing.

But there were no flaws. The obvious was being stated with simple clarity. Aliens had landed in Nebraska and the government was exerting great effort to keep that information secret.

Stupid nervous habit she scolded herself while smoothing the edge using her teeth as a smoothing plane. A mere single page was not a conversation. It was merely a conspiracy theory dreamed up by paranoid idle minds. Her’s was not idle, nor paranoid – or so she thought.

It was like the back of the dollar bill only in reverse. The image on the bill contained the illustration of a pyramid with an invisible top. All that stuff building block upon block until…nothing. This report stated a single fact, floating above a plane. But where was the support? Invisible, yet it had to be there.

Aliens! Why not fairies and elves? America. Nebraska?! Why not Los Angeles, the land of the waking dream, or New York, the land of the waking nightmare. Betty and Barney Hill would want to shake her hand.

In an unusual move, she pressed the buttons that would generate hard copy. A finger pointing, guilty!

Play invalid sound, load one in the background

To start there is a “beep” while the real audio loads in the background.
1. In the game object put the audio.
2. Put an audio listener too.
3. Reuse the Collision trigger script that played the sound.
4. Extend it to load audio as coprocess.
5. When the audio loads, swap it in.

public class ClickButton : MonoBehaviour {
bool clicked = false;
public float elapsedTime = 0.0f;

// Use this for initialization
void Start()
void Update()
if (clicked)
AudioSource audio = GetComponent();
if (!audio.isPlaying)
clicked = false;
var tmp = transform.position;
tmp.x += .08f;
transform.position = tmp;
void OnMouseDown()
var tmp = transform.position;
if (!clicked)
clicked = true;
tmp.x -= .08f;
clicked = false;
tmp.x += .08f;
transform.position = tmp;
IEnumerator LoadClip()
WWW www = new WWW(“”);

while (!www.isDone)
elapsedTime += Time.deltaTime;
yield return null;

// TODO – look for errors, try again, etc.
AudioSource audio = GetComponent();
audio.clip = www.GetAudioClip(false, false);

yield break;


Unity Tasty Tidbits

Move an object like a button press.

var tmp = transform.position;
tmp.x += .08f;
transform.position = tmp;

Respond to a button click

On a an object with box colllider.
“Is Trigger” is Checked.
Add the following script…
void OnMouseDown()
var tmp = transform.position;
if (!clicked)
clicked = true;
tmp.x -= .08f;
clicked = false;
tmp.x += .08f;
transform.position = tmp;

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.


Survival Shooter – Chapter 2

Add the main character, “player”

Open the models folder, find it drag-and-drop it.

Make sure he is centered at 0,0,0(origin)

Tag player as “player”


Animation controller. Move, turn, etc.

You will create a folder called Animation, in there create a  new Animation Controller called PlayerAC

Drag and drop that into the player.

Double click on the PlayerAC object to invoke the editor.

Now look at the player model and expand it.  There are some animations.  Drag and drop them into the Editor.

Make “Idle” the default. Right click, then “make default”, duh

Now we need to create the hooks so we can use these animations.  Create 2 new parameters.  IsWalking, Die

Now you can create some transitions that define how we logically go from one state to another.

Lets start with idle to move. Select idle, right click, choose make transition and link the event to move.  There is the link.

To edit the link,  click on it.  Then see the line.  Right click and find the Inspector.  Add the Condition IsWalking/True.

Make a reverse entry from move to idle with condition IsWalking/false

Since “die” can be called from any state,  create an event link from AnyState to Die.  Add the condition Die in the inspector.

That is it for now.


Back to char, add physics to our player – rigidbody(3d of course) and Capsule collider.

And of course sound. Add an audio source and the appropriate sound.


Move on to programming the movement.

You have:

FixedUpdate that runs on when rigid body moves

It calls three functions to do interesting things

Movement  – move our player

Turning — makes the camera follow the main guy around

Animating – set the “IsWalking” param of the animator we built above.

Because these programs were written for version 4, we can’t test the script until we fix the others.   Correct the missing references.


public class PlayerMovement : MonoBehaviour {
public float speed = 6;

private Vector3 movement;
private Animator anim;
private Rigidbody rb;

private int floormask; // raycast
private float camRayLength = 100f;

void Awake()
floormask = LayerMask.GetMask(“Floor”);
anim = GetComponent();
rb = GetComponent();

// physics update.
void FixedUpdate()
float h = Input.GetAxisRaw(“Horizontal”);
float v = Input.GetAxisRaw(“Vertical”);

Movement(h, v);
Animating(h, v);
void Movement(float h, float v)
movement.Set(h, 0, v);
movement = movement.normalized * speed * Time.deltaTime;
rb.MovePosition(transform.position + movement);
void Turning()
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast(camRay, out floorHit, camRayLength, floormask))
Vector3 playerToMouse = floorHit.point – transform.position;
playerToMouse.y = 0; // never leave the plane
Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
void Animating(float h, float v)
bool walking = (h != 0) || (v != 0);
anim.SetBool(“IsWalking”, walking);


Survival Shooter – Chapter 1

Start a 3d project

Find it!/content/40756

Load it into unity

Copy Environment prefab into scene

Copy lights prefab onto screen


We plan to use “Raycast” but don’t want to show on all the objects like the legos or the table.   [We know we are going to do something, but they arent specific.  Start by creating a quad called floor…]  This is the collider.

Create a quad – put it at origin, turn 90 on x.  Scale to 100×100

Name it “Floor”

Remove mesh-render component from floor.  You will see the collider (floor) outline.

Go to the properties window and at the top – change the layer to “Floor”


That is it for now.



Create a blank game object and name it to background-audio

Add the component (audio source)

Use circle-select to pick the audio clip.

Unckeck – play on awake,

Check loop

Adjust volume to 0.1



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


public GameObject hazard;


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.




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