I am having an issue with my Grape. I had an issue early into the course with the animation event not firing. I seem to be having the same issue. Previously i deleted all the animations and remade them and this fixed the issue. I have deleted them all twice now and the issue is still happening.
Basically the Attack trigger dosnt seem to be firing. The grape is also not stopping when attacking, which also suggests to be that the attack code isnt running. Im not sure why though. Its a direct copy of my slime which is working fine and there are no code errors appearing.
Also I have noticed at this section since altering the enemyai script for the grape that my ghost isnt functioning the same. It dosnt seem to be able to lock onto my player anymore.
Im not sure what I can provide for the grape issue.
As for th ghost the only thing that ive altered as far as I can see that affects both oft he these characters is the part of the enemyAi script that deals with setting the attack range.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyAI : MonoBehaviour
{
[SerializeField] private float roamChangeDirFloat = 2f;
[SerializeField] private float attackRange = 0f;
[SerializeField] private MonoBehaviour enemyType;
[SerializeField] private float attackCooldown =2f;
[SerializeField] private bool stopMovingWhileAttacking = false;
private bool canAttack = true;
private enum State {
Roaming,
Attacking
}
private Vector2 roamPosition;
private float timeRoaming = 0f;
private State state;
private EnemyPathfinding enemyPathfinding;
private void Awake(){
enemyPathfinding= GetComponent<EnemyPathfinding>();
state = State.Roaming;
}
private void Start(){
roamPosition = GetRoamingPosition();
}
private void Update (){
MovementStateControl();
}
private void MovementStateControl(){
switch (state)
{
default:
case State.Roaming:
Roaming();
break;
case State.Attacking:
Attacking();
break;
}
}
private void Roaming(){
timeRoaming += Time.deltaTime;
enemyPathfinding.MoveTo(roamPosition);
if (Vector2.Distance(transform.position, PlayerController.Instance.transform.position) < attackRange) {
state = State.Attacking;
}
if (timeRoaming > roamChangeDirFloat){
roamPosition = GetRoamingPosition();
}
}
private void Attacking(){
if (Vector2.Distance(transform.position, PlayerController.Instance.transform.position) > attackRange) {
state = State.Roaming;
}
if (attackRange != 0 && canAttack){
canAttack = false;
(enemyType as IEnemy).Attack();
if (stopMovingWhileAttacking) {
enemyPathfinding.StopMoving();
} else {
enemyPathfinding.MoveTo(roamPosition);
}
StartCoroutine(AttackCoolDownRoutine());
}
}
private IEnumerator AttackCoolDownRoutine(){
yield return new WaitForSeconds(attackCooldown);
canAttack = true;
}
private Vector2 GetRoamingPosition(){
timeRoaming = 0f;
return new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized;
}
}