void Awake() { vision = GetComponent <EnemyVision>(); attack = GetComponent <TurretAttack>(); death = GetComponent <Enemy_Death>(); childcount = transform.childCount; }
//mata al jugador o al enemigo cuando están activadas private void OnTriggerStay2D(Collider2D collision) { if (shooting) { Enemy_Death dead = collision.gameObject.GetComponent <Enemy_Death>(); if (dead != null) { dead.OnAttack(); } Death death = collision.gameObject.GetComponent <Death>(); if (death != null) { death.Dead(); } } }
//Permite matar al jugador o al enemigo cuando colisionan con la bala //La bala es destruida al colisionar con cualquier cosa. private void OnCollisionEnter2D(Collision2D collision) { death = collision.gameObject.GetComponent <Enemy_Death>(); if (death != null) { death.OnAttack(); } Death dead = collision.gameObject.GetComponent <Death>(); if (dead != null) { dead.Dead(); } Destroy(this.gameObject); }
void FixedUpdate() { // Testing functions if (!this.isBlighted && Input.GetKeyDown("b")) { this.BlightEnemy(); } if (!this.isBurned && Input.GetKeyDown("u")) { this.BurnEnemy(); } if (!this.isSlowed && Input.GetKeyDown("s")) { this.SlowEnemy(0.5f); } // Do fade-in if not opaque yet if (fadingIn) { FadeIn(); } // Do Blight & Burn damage if (this.isBlighted) { this.blightTimer -= Time.deltaTime; if (this.blightTimer <= 0) { this.BlightTick(); } } if (this.isBurned) { this.burnTimer -= Time.deltaTime; if (this.burnTimer <= 0) { this.BurnTick(); } } // Check health, die if health <= 0. if (this.health <= 0) { GameObject effect = (GameObject)Instantiate(this.deathEffect, this.transform.position, Quaternion.identity); Enemy_Death death = effect.GetComponent <Enemy_Death>(); death.setDirection(animator.GetInteger("Direction")); CrystalCounter temp = crystalCounter.GetComponent <CrystalCounter>(); temp.SetCrystals((int)(10 * UnityEngine.Random.Range(1.0f - .2f, 1.0f + .2f))); Destroy(effect, 0.5f); Destroy(this.gameObject); } // Check for "Rage" attribute and HP < 50% if (this.attributes.Contains("Rage") && this.health <= this.maxHealth / 2) { if (!this.isEnraged) { this.isEnraged = true; this.powerMultiplier += 1f; this.speedMultiplier += 1f; } } // Do regen this.regenTimer -= Time.deltaTime; if (this.regenTimer <= 0) { this.RegenTick(); } // Move if not stunned, otherwise reduce stun time if (!this.isStunned) { // Move the enemy towards the target waypoint this.transform.Translate(this.dir.normalized * this.speed * this.speedMultiplier * Time.deltaTime, Space.World); // Check if the waypoint has been reached if (Vector2.Distance(this.transform.position, this.target) <= this.waypointDetection) { this.waiting = true; } // Do random 'wait time' if applicable if (this.waiting == true) { if (this.waypointWaitTime > 0) { this.waypointWaitTime -= Time.deltaTime; } else { this.GetNextWaypoint(); } } } else { this.StunTick(); } time++; }