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