Je n'avait pas de problème avec ce script pour les dégat mais lorsque j'ai voulue rajouter un bonus pour donner de la vie il y a eu une erreur que je n'arrive pas à régler.
Voici le script:
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;
public Animator animator2;
public Animator animator3;
public Rigidbody2D rb;
public float maxJump;
public float vitesse;
private float timer = 0.0f;
private float timer2 = 0.0f;
private float timer3 = 0.0f;
private float timer4 = 0.0f;
private float waitTime = 0.5f;
private float waitTime2 = 0.3f;
private float waitTime3 = 0.19f;
private float waitTime4 = 0.1f;
private bool degat = false;
private bool degat2 = false;
private bool degat3 = false;
private bool degat4 = false;
private bool bonus = 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;
timer2 += Time.deltaTime;
timer3 += Time.deltaTime;
timer4 += Time.deltaTime;
if(timer2 > waitTime2)
{
timer2 = 0.0f;
if (degat2)
{
StartCoroutine(degat_50());
}
}
if(timer > waitTime)
{
timer = 0.0f;
if (degat)
{
StartCoroutine(degat_100());
}
}
if(timer3 > waitTime3)
{
timer3 = 0.0f;
if (degat3)
{
StartCoroutine(degat_50_2());
}
}
if(timer4 > waitTime4)
{
timer4 = 0.0f;
if (degat4)
{
animator2.SetBool("fermer", true);
animator.SetBool("mort", true);
life = life - 300;
StartCoroutine(Vitesse());
}
}
if (bonus)
{
animator3.SetBool("récolter", true);
if(life = maxlife)
{
life = life + 0;
}
else
{
life = life + 100;
}
}
}
void OnTriggerEnter2D(Collider2D col){
if(col.gameObject.CompareTag("Obstacle3"))
{
degat2 = true;
}
if(col.gameObject.CompareTag("Obstacle2"))
{
degat = true;
}
if(col.gameObject.CompareTag("Obstacle4"))
{
degat3 = true;
}
if(col.gameObject.CompareTag("Obstacle5"))
{
degat4 = true;
}
if(col.gameObject.CompareTag("Bonus"))
{
bonus = true;
}
}
void OnTriggerExit2D(Collider2D col){
if(col.gameObject.CompareTag("Obstacle3"))
{
degat2 = false;
}
if(col.gameObject.CompareTag("Obstacle2"))
{
degat = false;
}
if(col.gameObject.CompareTag("Obstacle4"))
{
degat3 = false;
}
if(col.gameObject.CompareTag("Obstacle5"))
{
degat4 = false;
}
if(col.gameObject.CompareTag("Bonus"))
{
bonus = false;
}
}
IEnumerator degat_100()
{
animator.SetBool("degat", true);
life = life - 100;
yield return new WaitForSeconds (0.5f);
animator.SetBool("degat", false);
}
IEnumerator degat_50()
{
animator.SetBool("degat", true);
life = life - 50;
yield return new WaitForSeconds (0.5f);
animator.SetBool("degat", false);
}
IEnumerator degat_50_2()
{
animator.SetBool("degat", true);
rb.velocity += new Vector2(0, maxJump);
life = life - 50;
yield return new WaitForSeconds (0.5f);
animator.SetBool("degat", false);
}
void SetVelocity(float xVelocity, float yVelocity){
rb.velocity = new Vector2(0, 0);
rb.velocity += new Vector2(xVelocity, yVelocity);
}
IEnumerator Vitesse()
{
yield return new WaitForSeconds (0.2f);
SetVelocity(vitesse, 0);
}
}
Pouvez-vous m'aider.Assets\Script\Personnage\Coeur_1.cs(90,16): error CS0029: Cannot implicitly convert type 'float' to 'bool'
Merci d'avance.