// Override of the Combat function since this behaviour needed extra combat components. protected override void Combat() { if (m_ShotTimer <= 0) { if (getTarget() == null) { return; } transform.LookAt(getTarget().transform.position); if (m_EnemyAI.m_UCombat) { switch (m_CurrentCombatState) { case CombatStates.Regular: EnemyAnimator.playAnimation(AnimatorGnomeMage.Animations.Attack); if (m_CombatComponent != null) { m_CombatComponent.Combat(getTarget()); } break; case CombatStates.Cloned: if (m_ClonedCombat != null) { m_ClonedCombat.Combat(getTarget()); } break; } } m_ShotTimer = Random.Range(m_MinTimeBetweenShots, m_MaxTimeBetweenShots); } }
// The following functions must be called to update any of the components in order to make sure the // enemy controller hasn't taken control of any of them protected virtual void Combat() { if (m_EnemyAI.m_UCombat) { if (m_CombatComponent != null) { m_CombatComponent.Combat(getTarget()); } } }
// Update is called once per frame new void Update() { base.Update(); if (PauseScreen.shouldPause(PAUSE_LEVEL)) { return; } // If the clones active timer is done or if the original is dead then kill it off if (m_ActiveTimer <= 0.0f || m_OriginalIsDead) { instantKill(); } // If the target is not null look at it Vector3 targetPos = new Vector3(m_Target.transform.position.x, 0, m_Target.transform.position.z); Vector3 myPos = new Vector3(transform.position.x, 0, transform.position.z); if (m_Target != null) { transform.forward = targetPos - myPos; } //Attack if the shot timer is over if (m_ShotTimer <= 0) { if (m_CombatComponent != null) { m_CombatComponent.Combat(m_Target); } m_ShotTimer = m_TimeBetweenShots; } // Move if (m_MovementComponent != null) { m_MovementComponent.Movement(m_Target); } m_ActiveTimer -= Time.deltaTime; }
// Update is called once per frame public override void update() { EnemyAnimator.playAnimation(AnimatorGnomeMage.Animations.Hover); //Grab the current target setTarget(Target()); // If there is no target either the player is dead, gone or something went wront so switch to the idle state // OR // If its time to leave combat set the current state to idle if (getTarget() == null || LeaveCombat(getTarget().transform)) { m_EnemyAI.SetState(EnemyAI.EnemyState.Idle); return; } // If we are in attack range switch to the attack state float dist = Vector3.Distance(transform.position, getTarget().transform.position); if (dist <= Constants.MAGE_ATTACK_RANGE) { m_EnemyAI.SetState(EnemyAI.EnemyState.Attack); return; } // move Movement(); if (m_ShotTimer <= 0) { // Manually doing the check if the controller has taken over combat because the base does not have combat included if (m_EnemyAI.m_UCombat) { m_CombatComponent.Combat(getTarget()); } m_ShotTimer = m_TimeBetweenShots; } m_ShotTimer -= Time.deltaTime; }