VFX to Visualize Damage on Player (2D Sprite animation)
To animate the player’s damage in this 2D Space Shooter, a three-step approach will be taken to visualize damage on the ships’ wings. This is the animation that is being duplicated to show two damage points taken.
Once the fire flare is animated and duplicated, translate each flare to the end of each wing and disable the game object. The explosion prefab will be used to signal the third hit when the player dies and the game is over.
The code detects the current health in order to set each damage effect on.
[SerializeField]
private GameObject _wFR;
[SerializeField]
private GameObject _wFL;
[SerializeField]
private GameObject _explosionFire;
public void Start()
{
_wFL.SetActive(false);
_wFR.SetActive(false);
}
public void Damage()
{
if (_ShieldEnabled == true)
{
_ShieldEnabled = false;
StartCoroutine(ShieldTurnOff());
_uiManager.NewTakedown(1);
return;
}
else if (_ShieldEnabled == false)
{
_currentHealth --;
_uiManager.UpdateLives(_currentHealth);
if (_currentHealth == 2)
{
_wFR.SetActive(true);
}
if (_currentHealth == 1)
{
_wFL.SetActive(true);
}
if (_currentHealth < 1)
{
_spawnManager.OnPlayerDeath();
_uiManager.GameOver();
Instantiate(_explosionFire, transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
}
}
As the VFX of the wing’s fire is simply set to active, the explosion effect is Instantiated right before destroying the player. The explosion effect has its own script that destroys the instantiated object after 2 seconds of starting.
Simple code that provokes marvelous UX signifiers.