Answer the question
In order to leave comments, you need to log in
How to make hp taken away with some delay?
Here is my code:
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);
}
}
}
HP is taken away very quickly, in less than a second, and it is necessary that after taking one hp there was a delay and damage was done again.
Answer the question
In order to leave comments, you need to log in
Set the delay parameter, cock it when taken away, see the difference when repeating
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question