[DB-AL] Problème avec les animation.

Pour les scripts écrits en C#
Règles du forum
Merci de respecter la NOMENCLATURE suivante pour vos TITRES de messages :

Commencez par le niveau de vos scripts
DB = Débutant
MY = Moyen
CF = Confirmé

Puis le domaine d'application
-RS = Réseau
-AL = Algorithmie

Exemple :

[DB-RS] Mouvement perso multijoueur
MGameur
Messages : 28
Inscription : 22 Mars 2020 21:23

[DB-AL] Problème avec les animation.

Message par MGameur » 30 Mars 2020 12:48

Bonjour,
J'ai un gros problème avec une animation, le problème c'est que quand je rentre dans le premier cœur, il me fait l'animation de récolte donc je le duplique mais des que je rentre dans le second il ne me fait pas l'animation de récolte or si je met dans le controller (récolter = true) il me fait l'animation. Je vous met en fiche des image des controller et animation.
Pouvez vous m'aider car je ne trouve pas la solution.
Merci d'avance pour votre aide.

PS: J'ai beau remettre que (récolter = false) sa ne change rien. Et le second cœur et bien reconnue car il me redonne de la vie.

Voici la partie du code que utilise le Cœur :

Code : Tout sélectionner

using UnityEngine.UI;

public class Coeur_1 : MonoBehaviour
{
	public Animator animator3;
	private bool bonus = false;
void update
{
	if (bonus)
        {
            animator3.SetBool("récolter", true);
            if(life == maxlife)
            {
                life = life + 0;
            }
            else
            {
                life = life + 100;
            }
        }

        if (life <= 0)
            {
                animator.SetBool("mort", true);
                StartCoroutine(Vitesse());
            }

        if (life > maxlife)
            {
                life = maxlife;
            }
}
    
IEnumerator Vitesse()
    {
        yield return new WaitForSeconds (0.2f);
        SetVelocity(vitesse, 0);
    }
}

Si vous voulait tout le script le voici :

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 timer5 = 0.0f;
    private float timer6 = 0.0f;
    private float timer7 = 0.0f;
    private float timer8 = 0.0f;
    private float waitTime = 0.5f;
    private float waitTime2 = 0.3f;
    private float waitTime3 = 0.15f;
    private float waitTime4 = 0.1f;
    private float waitTime5 = 0.25f;
    private float waitTime6 = 0.2f;
    private float waitTime7 = 0.1875f;
    private float waitTime8 = 0.18f;
    private bool degat = false;
    private bool degat2 = false;
    private bool degat3 = false;
    private bool degat4 = false;
    private bool degat5 = false;
    private bool degat6 = false;
    private bool degat7 = false;
    private bool degat8 = 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;
        timer5 += Time.deltaTime;
        timer6 += Time.deltaTime;
        timer7 += Time.deltaTime;
        timer8 += 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());
                StartCoroutine(Ouvert());
            }  
        }

        if (bonus)
        {
            animator3.SetBool("récolter", true);
            if(life == maxlife)
            {
                life = life + 0;
            }
            else
            {
                life = life + 100;
            }
        }

        if (life <= 0)
            {
                animator.SetBool("mort", true);
                StartCoroutine(Vitesse());  
            }

        if (life > maxlife)
            {
                life = maxlife;
            }

        if(timer5 >= waitTime5)
        {
            timer5 = 0.0f;
            if (degat5)
            {
                StartCoroutine(degat_100());
            }
        }

        if(timer6 >= waitTime6)
        {
            timer6 = 0.0f;
            if (degat6)
            {
                StartCoroutine(degat_50());
            }
        }

        if(timer7 >= waitTime7)
        {
            timer7 = 0.0f;
            if (degat7)
            {
                StartCoroutine(degat_100());
            }
        }

        if(timer8 >= waitTime8)
        {
            timer8 = 0.0f;
            if (degat8)
            {
                StartCoroutine(degat_50());
            }
        }
    }

    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; 
		}

        if(col.gameObject.CompareTag("Obstacle6"))
        {
			degat5 = true; 
		}

        if(col.gameObject.CompareTag("Obstacle7"))
        {
			degat6 = true; 
		}

        if(col.gameObject.CompareTag("Obstacle8"))
        {
			degat7 = true; 
		}

        if(col.gameObject.CompareTag("Obstacle9"))
        {
			degat8 = 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; 
		}

        if(col.gameObject.CompareTag("Obstacle6"))
        {
			degat5 = false; 
		}

        if(col.gameObject.CompareTag("Obstacle7"))
        {
			degat6 = false; 
		}

        if(col.gameObject.CompareTag("Obstacle8"))
        {
			degat7 = false; 
		}

        if(col.gameObject.CompareTag("Obstacle9"))
        {
			degat8 = 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);
    }

    IEnumerator Ouvert()
    {
        yield return new WaitForSeconds (0.9f);
        animator2.SetBool("ouvrir", true);
    }
}
Pièces jointes
5.PNG
5.PNG (100.08 Kio) Consulté 1910 fois
6.png
6.png (510.35 Kio) Consulté 1910 fois
7.png
7.png (187.95 Kio) Consulté 1910 fois

Répondre

Revenir vers « (C#) CSharp »