Other Effects, Visualizers and Behaviours
Revisado con versión: 2017.2
Adding Visualization for Health
To show the player how much health an Agent or Tower has remaining, we can do the following:
Drag in the HealthBar Prefab from Prefabs/UI/HUD and make it a child of the GameObject with a Tower, AttackingAgent, or FlyingAgent component
Select the HealthBar object and drag its parent GameObject into the Damageable Behaviour field
Understanding the HealthVisualizer component
It is also common to have health bars appear over objects in the game that have health. To visualise the health of a Damageable or DamageableBehaviour, we can add a HealthVisualiser to the object.
Note that the Starter Kit comes with a Health Bar prefab, which can be used instead of making assets from scratch.
Here we can set a reference to a Prefab, and the HealthVisualiser script will attach the health bar to the related object.
This is the bar that will show how much health the Agent or Tower has remaining. It will become smaller as the object it is attached to takes damage and loses health.
This bar appears behind the health bar, and becomes visible when the object takes damage. This is useful to show the difference between the unit’s current health and its maximum health.
Show When Full
If this is turned off, the Tower or Agent will only display its health bar after it has first taken damage.
Adding Visualization for Death
Currently, Towers and Agents will simply be removed from the stage when they are destroyed. We can make this process more dramatic and noticeable to the player by adding effects when they are destroyed.
Add a DeathEffect component to a GameObject with a Tower, AttackingAgent, or FlyingAgent component
Drag the Tower or Agent Prefab into the Damageable Behaviour field
Drag a Particle System that should play on the unit’s death into the Death Particle System Prefab field
If the Particle System’s position is not quite where it should be, use the Death Effect Offset to adjust it
Understanding the DeathEffect component
Here we can set a reference to a Prefab, and the DeathEffect script will create a particle effect when that object is killed.
Death Particle System Prefab
This can be used to assign a particle prefab that will be created when the Tower or Agent is destroyed.
Death Effect Offset
This can be used to adjust the position of the Particle System if it appears in the wrong place in relation to the unit’s death position.
Adding a Tower that debuffs Agents
We can also add the ability for a Tower to slow Agents down when they are near it. This can work on its own or in addition to the Tower attacking the Agents.
Add a SlowAffector component to the Affector GameObject
Drag the Tower’s Targetter Game Object into the Targetter field
Set the Slow Factor value to a desirable amount
Drag an effect Prefab into the Slow Fx Prefab
Understanding the SlowAffector component
A short string to describe what the script’s effect is.
The color of the range visualizer for the Tower ghost.
References the Tower’s Targetter component. This ensures that the SlowAffector effect can be applied to Agents targeted by the Targetter.
The modifier applied to the Agent’s speed when it is in the Tower’s radius.
Slow Factor Format
A string that shows the player how much Agents in the Tower’s effect radius are slowed down.
Enter Particle System
The Particle System that will play when the Agent first enters the Tower’s effect radius.
Slow Fx Prefab
The Particle System Prefab that will play while the slow effect is applied to an Agent.
The Audio Source that should play while the slow effect is applied to an Agent.
Adding a Tower that passively adds currency
We can also add the ability for a Tower to passively generate currency over time:
Add a CurrencyAffector component to the Affector GameObject
Set the Constant Currency Addition field to the amount of currency that should be added at set intervals
Set the Constant Currency Gain Rate to the number of times the addition should be made per second
Understanding the CurrencyAffector component
The name of the currency.
Constant Currency Addition
The number of currency units added to the player’s total every time the script adds currency.
Constant Currency Gain Rate
The number of times per second the script will add currency to the player’s total.
String to show players what the currency is and how much is added.
The Audio Source that will play whenever the Tower adds currency to the player’s total.
The Particle System that plays whenever the Tower adds currency to the player’s total.
Adding rewards for destroying Agents
In order to give the player more currency when their Towers destroy enemy Agents, we can take the following steps:
Add a LootDrop component to the Agent Prefab
Set the value of the Loot Dropped field to the amount of currency we want to add to the player’s total when they destroy the enemy
Understanding the LootDrop component
We might choose to start the player off with only enough currency to place one or two Towers, and have them build up more over time by destroying enemies. This functionality is made possible by the LootDrop component
This is the amount of currency that will be added to the player’s total when the Agent is destroyed. Conventionally, weaker enemies will give smaller amounts of currency.
- Introduction to Tower Defense Template (Lección)
- Towers (Lección)
- Agents (Lección)
- Targeting and Firing (Lección)
- Other Effects, Visualizers and Behaviours (Lección)
- Setting Up a Stage in Tower Defense Template (Lección)
- Camera (Lección)
- Adding UI (Lección)
- Adding Input (Lección)
- Action Game Framework (Lección)