Je suis en train de faire un jeu et j'ai des problème sur les dégat. Voici le code:
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Coeur_1 : MonoBehaviour
{
public Image Coeur;
public float life;
public float maxlife;
public Animator animator;
private float timer = 0.0f;
private float timer2 = 0.0f;
private float waitTime = 0.5f;
private float waitTime2 = 0.0f;
private bool degat = false;
private bool degat2 = false;
// Start is called before the first frame update
void Start()
{
life = maxlife;
}
// Update is called once per frame
void Update()
{
Coeur.fillAmount = life / maxlife;
timer += Time.deltaTime;
if(timer2 > waitTime2)
{
timer2 = 0.0f;
if (degat2)
{
StartCoroutine(dégat_50());
}
}
if(timer > waitTime)
{
timer = 0.0f;
if (degat)
{
StartCoroutine(dégat_100());
}
}
}
void OnTriggerEnter2D(Collider2D col){
if(col.gameObject.CompareTag("Obstacle3"))
{
degat2 = true;
}
if(col.gameObject.CompareTag("Obstacle2"))
{
degat = true;
}
}
void OnTriggerExit2D(Collider2D col){
if(col.gameObject.CompareTag("Obstacle3"))
{
degat2 = false;
}
if(col.gameObject.CompareTag("Obstacle2"))
{
degat = false;
}
}
IEnumerator dégat_100()
{
animator.SetBool("dégat", true);
life = life - 100;
yield return new WaitForSeconds (0.5f);
animator.SetBool("dégat", false);
}
IEnumerator dégat_50()
{
animator.SetBool("dégat", true);
life = life - 50;
yield return new WaitForSeconds (0.5f);
animator.SetBool("dégat", false);
}
}
Pouvez vous m'aider a faire en sorte qu'il y est plusieurs type de dégat.
Merci d'avance.