public void OnTriggerEnter2D(Collider2D collision) { if (isDead) { return; } if (!collision.transform.tag.Equals("Indestructible")) { Tir proj = collision.gameObject.GetComponent <Tir>(); float modif = GameManager.gameManager.gameData.eTab[(int)proj.effect, (int)mob.elem]; mob.ModifPV(-(int)(proj.GetDamage() * modif)); if (proj.effect.Equals(Monstre.element.terre)) { RaycastHit2D[] tabTarget = Physics2D.CircleCastAll(this.transform.position, 2, Vector2.zero); foreach (RaycastHit2D t in tabTarget) { if (t.collider.gameObject.tag == "Ennemy") { t.collider.gameObject.GetComponent <MonsterController>().mob.ModifPV(-proj.GetDamage()); } } } else if (proj.effect.Equals(Monstre.element.feu)) { mob.SetDotData(1, 3); } Destroy(collision.gameObject); } }
void FireAnim(Tir tir) { if (tir.CanFire) { if (tir.Rounds > 0) { anim.SetTrigger("fire"); AnimFlame.SetTrigger("flame"); } } }
// Update is called once per frame void Update() { Tir tir = GetComponent <Tir> (); if (tir.IsAuto) { if (Input.GetButton("Fire1")) { FireAnim(tir); } } else { if (Input.GetButtonDown("Fire1")) { FireAnim(tir); } } if (Input.GetKeyDown(KeyCode.R)) { tir = GetComponent <Tir> (); if (tir.Rounds < tir.MaxRounds && tir.Magazines > 0) { anim.SetTrigger("reload"); } } if ((Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) && !Input.GetButton("Fire3")) { anim.SetBool("walking", true); anim.SetBool("running", false); } else { anim.SetBool("walking", false); } if (Input.GetAxis("Vertical") != 0 && Input.GetButton("Fire3")) { anim.SetBool("walking", false); anim.SetBool("running", true); } else { anim.SetBool("running", false); } }
void Start() { mouseOver = true; //On établi l'accès entre ce script et celui du GameObject prefab_Tir prefab_tir_script = (Tir)prefab_tir.GetComponent(typeof(Tir)); //On vide la file d'attente de la tour, on s'assure qu'elle commence à vide. file.Clear(); //On fait en sorte que la tour n'attaque pas immédiatement mode_attaque = false; //On récupère la taille de la portée de la tour portee = GetComponent <SphereCollider>(); }
IEnumerator attack() { while (file.Count > 0) //Tant que la cible est toujours dans la liste { if (file[0] != null) { prefab_tir_script = (Tir)prefab_tir.GetComponent(typeof(Tir)); //Le projectile vise l'ennemie numero 1 (en position zéro dans la liste) prefab_tir_script.cible = file[0].gameObject; //Le projectile de la TOUR CANON vise l'ennemie numero 1 (en position zéro dans la liste) S'IL n'as pas déjà une destination if (prefab_tir_script.GetDestination == false) { prefab_tir_script.cibleTirCanon = file[0].transform.position; } //La tour tir un nouveau projectile //Vector3 pos = new Vector3(transform.position.x + Random.Range(-1, 1), transform.position.y + Random.Range(1, 3), transform.position.z); //Instantiate(prefab_tir, pos, transform.rotation); if (IsPoison) { prefab_tir_script.IsPoison = true; } if (IsGel) { prefab_tir_script.IsGel = true; } if (IsRadiation) { prefab_tir_script.IsRadiation = true; } Instantiate(prefab_tir, transform.position, transform.rotation); switch (type) { case "rafale": SoundManagerEvent.emit(SoundManagerType.RAFALE, this.gameObject); break; case "sniper": SoundManagerEvent.emit(SoundManagerType.SNIPER, this.gameObject); break; case "canon": SoundManagerEvent.emit(SoundManagerType.CANON, this.gameObject); break; } tir_instance = Instantiate(prefab_tir, transform.position, transform.rotation) as GameObject; if (IsPoison) { tir_instance.GetComponent <Tir>().IsPoison = true; } if (IsGel) { tir_instance.GetComponent <Tir>().IsGel = true; } if (IsRadiation) { tir_instance.GetComponent <Tir>().IsRadiation = true; } //Maintenant on attend le couldown avant de relancer un projectile yield return(new WaitForSeconds(cooldown)); } else { break; } } if (file.Count > 0) //Si il y a des éléments dans le tableau { //Normalement à ce stade la cible est morte, juste pour vérifier on fait ce if if (file[0] == null) //Si il y n'y a pas d'élément en 1ère position on refresh la liste pour en trouver un { refresh(); } } else if (file.Count == 0) //Si il n'y a plus de cible après celle qui vient de disparaître { //Alors on indique à la tour qu'elle est à nouveau prête à tirer mode_attaque = false; //On efface la dernière cible, elle est loin ou détruite prefab_tir_script.cible = null; } yield return(null); }