Quick Start 5: Killables & World Variables

Picking up where we left off in Quick Start 4, in this one we're going to use the Killable script, which is crazy powerful, as well as World Variables.

     
  1. Killable is another component you can add to any Game Object. It can do combat (Hit Points / Attack Points) as well as prefab replacement, and a slew of other features. All the Example Scenes use Killables extensively, so you should definitely take a look at those. For our purposes, we are going to show some high level functionality. Go ahead and create a new Sphere Game Object in the Hierarchy named "Enemy" and add the Killable component to it from the Inspector. It will look like this:
     

  2.  
  3. Get rid of the Pool Boss error by entering Preload Qty of 10 and clicking "Create Pool Boss Item".
  4.  
  5. With default settings, Killable will take damage from any trigger or collision with any Layer or Tag, has no prefabs to spawn during "death", "damage", "deal damage" or "despawn", does not inflict Knockback and doesn't modify any World Variables. Let's change a few of those.
  6.  
  7. Change "Start Hit Points" to 3 so we can get a few points of damage in before it dies.
  8.  
  9. Expand the "Damage Prefab Settings & Events" section. It looks like this:
  10.  

     
  11. Change "Spawn Frequency" to "Per Hit", then change "Damage Prefab Type" to "Specific". For "Damage Prefab", drag in your sphere prefab. Give it a Spawn Offset of 5/5/5, just so we'll be able to see it.
  12.  
  13. Expand the "Death Prefab Settings & Events" section. It looks like this:
     

  14.  
  15. Drag in your Capsule prefab for "Death Prefab". Now you'll see additional fields:
     

  16.  
  17. Change "Spawn Quantity" to 3 and "Incremental Offset" to 3/3/3, again just so you can see it.
  18.  
  19. Okay, our Killable is ready to go for Damage and Death Prefabs. Suppose we also want to get 200 Score and 10 Experience Points when it's killed? Easy.
  20.  
  21. First, we will need to make sure we have the World Variables we want to modify. Click on the "World Variables" button in the Core GameKit logo banner. It will look like this now:
     

  22.  
  23. Fortunately for us, it looks like Score and Experience Points are already there. Go ahead and delete "Game Currency", "Lives" and "Health" World Variables. Let's create another World Variable so we know how:
       
    • For "New Variable Name", enter "Enemies Killed".
    •  
    • For "New Variable Type", select "Integer".
    •  
    • Click "Create Variable".
  24.  
  25. Now let's make it so the death of "Enemy" modify all those World Variables. Select "Enemy" in the Hierarchy and scroll down to the "Death World Variable Modifier Scenarios" and expand it. It will look like this:
     

  26.  
  27. For each World Variable we want to modify, we'll need to add a row:
       
    • Select "Score" from the "Add Variable Modifier" dropdown. It creates a row underneath. Add rows for "Experience Points" and "Enemies Killed" as well.
    •  
    • Modify the value for Score (numeric textbox with an "I" indicating "Integer" next to it) to 200.
    •  
    • Modify the value for Experience Points to 10.
    •  
    • Modify the value for Enemies Killed to 1.
  28.  
  29. It should look like this now:
     

 
  • Okay, we're ready to test it all out! Press play and then select "Enemy" in the Hierarchy. You will notice that it has green buttons for "Kill" & "Take 1 Damage" among others. Pool Boss also has icons for these at runtime for bulk usage if you remember.
  •  
  • Click "Take 1 Damage" and watch the Damage Prefabs spawn. Click it 2 more times and the Death Prefabs will spawn as well. Now click on the World Variables button on the Core GameKit logo banner and see that your Score, Experience Points and Enemies Killed have all been modified automatically.
  •  

    That's it for this Quick Start!

     

    Next: Quick Start 6: Using Addressables with Pool Mini-Boss