To unit test a health script class, follow these steps:
- Create a new 3D Unity project.
- In the Package Manager panel window, you have the latest version of the Test Framework package installed.
- Create a new folder named _Scripts.
- Inside your _Scripts folder, create a new Health.cs C# script class containing the following:
using UnityEngine;
using System.Collections;
public class Health
{
private float _health = 1;
public float GetHealth()
{
return _health;
}
public bool AddHealth(float heathPlus)
{
if(heathPlus > 0){
_health += heathPlus;
// ensure never more than 1
if(_health > 1) _health = 1;
return true;
} else {
return false;
}
}
public bool KillCharacter()
{
_health = 0;
...