The Death component that we are about to add has the same template as the Rotator component that we created in the last section. Let's add it by going through the following steps and taking a look at the code:
- In the WhackABox project root, create a new class called Death.cs.
- Replace the code in the class with the following code:
using Urho;
using System;
namespace WhackABox
{
public class Death : Component
{
private float deathTtl = 1f;
private float initialScale = 1;
public Action OnDeath { get; set; }
public Death()
{
ReceiveSceneUpdates = true;
}
public override void OnAttachedToNode(Node node)
{
initialScale = node.Scale.X;
}
protected override void OnUpdate(float timeStep)
{
Node.SetScale(deathTtl * initialScale);
if (deathTtl < 0)
{
Node.Remove();
}
...