/// <summary> /// The on unit hit function. /// This function is called as an animation event function in the attack animation. /// </summary> public void OnUnitHit() { if (Vector3.Distance(this.Currenttarget.transform.position, this.transform.position) > this.mystats.Attackrange) { this.enemycontroller.SetBool("Walk", false); this.navagent.SetDestination(this.transform.position); this.enemycontroller.SetTrigger("Idle"); } else { this.enemycontroller.SetTrigger("Idle"); this.enemycontroller.SetBool("Walk", false); IUnit u = this.target as IUnit; u.AutoTarget(this.gameObject); this.target.TakeDamage(this.mystats.Strength); // If unit is not null if (UnitController.Self.Unithit != null && UnitController.Self.Unithit.GetComponent <Stats>().Health > 0) { // Start a coroutine to print the text to the screen - // It is a coroutine to assist in helping prevent text objects from // spawning on top one another. this.StartCoroutine(UnitController.Self.CombatText(UnitController.Self.Unithit, Color.white, null)); } } }
/// <summary> /// The attack function gives the enemy functionality to attack. /// </summary> public void Attack() { if (this.timebetweenattacks >= this.mystats.Attackspeed && Vector3.Distance(this.Currenttarget.transform.position, this.transform.position) <= this.mystats.Attackrange) { Debug.Log("Enemy attacked!"); IUnit u = this.target as IUnit; u.AutoTarget(this.gameObject); this.target.TakeDamage(5); this.timebetweenattacks = 0; } }