void Update() { //Debug.Log(currentState); switch (currentState) { case (FrogAiStates.Patroling): PatrolingState(); break; case (FrogAiStates.AttackNear): AttackNearState(); break; case (FrogAiStates.AttackFar): AttackFarState(); break; case (FrogAiStates.Seeking): SeekingState(); break; } if (currentTargetEntity != null && Vector3.Distance(currentTargetEntity.transform.position, transform.position) > visionDistance) { CancelInvoke(); CurrentState = FrogAiStates.Patroling; currentTargetEntity = null; } }
void CheckTargetVisible() { if (currentTargetEntity == null) { CancelInvoke(); CurrentState = FrogAiStates.Patroling; return; } RaycastHit hit; if (Physics.Linecast(head.position, currentTargetEntity.transform.position, out hit)) { //Debug.Log(string.Format("Linecast hit {0}", hit.collider.gameObject)); BaseEntity other = hit.collider.gameObject.GetComponent <BaseEntity>(); if (other != currentTargetEntity && other != this.GetComponent <BaseEntity>()) { if (CurrentState == FrogAiStates.AttackNear) { CurrentState = FrogAiStates.Seeking; currentTarget = hit.point; } } else if (other == currentTargetEntity) { CurrentState = FrogAiStates.AttackNear; } } }
void EntityDeathDetected(BaseEntity died) { if (currentTargetEntity == died) { CurrentState = FrogAiStates.Patroling; currentTargetEntity = null; } }
public override void AttackedBy(BaseEntity attacker) { //Debug.Log(string.Format("attacked by {0}",attacker)); if (attacker != null) { currentTargetEntity = attacker; CurrentState = FrogAiStates.AttackNear; } }
void SeekingState() { mover.Aggressive = false; mover.LookAtTarget(currentTarget); mover.JumpTowards(); float distanceToTarget = Vector3.Distance(transform.position, currentTarget); if (distanceToTarget < 3) { CurrentState = FrogAiStates.Patroling; //currentTargetEntity = null; } }
void CheckIfEnemy(Collider col) { BaseEntity other = col.gameObject.GetComponent <BaseEntity>(); if (other == null) { return; } if (other == this.GetComponent <BaseEntity>()) { return; } else { if (other.Team != this.GetComponent <BaseEntity>().Team) { CurrentState = FrogAiStates.AttackNear; mover.CurrentTarget = other.transform; currentTargetEntity = other; } } }