I wanted the player to get damage every time they are close to the enemy with one damage per second, but the code does not load the delay.
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
playerDistance = Vector2.Distance (player.position, transform.position);
if (playerDistance < 2f) {
StartCoroutine (Wait ());
} else if (playerDistance > 2f) {
StopAllCoroutines ();
}
}
IEnumerator Wait (){
player.GetComponent<PlayerHealth> ().HurtPlayer (damageToGive);
yield return new WaitForSeconds (10);
}
}