Вот мой код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class HealthSystem : MonoBehaviour
{
public int hp;
public Image[] lives;
public Sprite fullLive;
public float transitionTime = 3f;
public Sprite emptyLive;
private Enemy ensc;
public int numberOfLives;
public GameObject dmg;
public GameObject vs;
Animator anim;
void Start(){
vs.SetActive(false);
ensc = GetComponent<Enemy>();
}
void Update()
{
if (hp > numberOfLives)
{
hp = numberOfLives;
}
for (int i = 0; i < lives.Length; i++){
if (i < hp){
lives[i].sprite = fullLive;
} else {
lives[i].sprite = emptyLive;
}
if (i < numberOfLives){
lives[i].enabled = true;
} else {
lives[i].enabled = false;
}
if (hp == 0) {
SceneManager.LoadScene("Menu");
}
}
}
void OnTriggerStay2D(Collider2D col){
if (col.CompareTag("EnemyDefolt")){
StartCoroutine(ToWait());
hp = hp - 1;
}
IEnumerator ToWait()
{
yield return new WaitForSeconds(10f);
}
}
}
Хп отнимается очень быстро, менее чем за секнду, а нужно чтобы после отнятия одного хп была задержка и снова наносился урон.