To track the player and enemy's health, we need variables to track how much health both have and how much damage both can do to each other.
For this, open up playerScript and add variables called health and damage at the top of the class. Then, set the value of the health variable to 100 and that of the damage variable to 10. So, the player will start with a health of 100, and when they hit the enemy, they will do a damage of 10 to the enemy:
using UnityEngine;
using System.Collections;
public class playerScript : MonoBehaviour {
public int health = 100;
public int damage = 20;
private Animator anim;
// other code
}
Similarly, add the same code as that of playerScript class to the enemyScipt class as well. Since we want to be fair, we will set the enemy's health to be 100 as well and set the damage that they can do to 10...