hi guys, I’m having trouble with my attack animation to run at the same time as my bullet gets instantiated. I intend that each time the enemy’s attack animation plays, a bullet also gets instantiated.
But, its either a barrage of bullets get instantiated as the animation plays or its just the bullets or the animation.
What I did is, I have a CHILD attached to the enemy, its function is to detect the target’s approach by having the “isTrigger” checked in the boxcollider.
Once the target entered the boxCollider, the enemy will shoot bullets synchronized with the animation.
Use a .SetTrigger() and trigger instead of bool as a property inside your controller.
Add a backward transition from your attacking state to the walking state (if it doesn’t exist), and you should be good.
hi guys just an update, I tried the scene animation as suggested by vergil, everything went fine with synchronization until its time to drain my hp with each attack, I did check just 1 frame of the attack animation collider to make that the point the hp gets drained but the hp still drains so fast
this is the 2 scripts, I have a player who will be attacked and an enemy…the enemy has 2 child, 1 fot the weapon the other to detect the player trigger…the player has setTrigger, the 2 child has setTrigger each with the attack script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attack : MonoBehaviour {
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.name.Equals("Girl"))
{
Zombie.isAttacking = true;
}
}
void OnTriggerExit2D(Collider2D col)
{
if (col.gameObject.name.Equals("Girl"))
{
Zombie.isAttacking = false;
}
}
}
the enemy reverts back to walking which solved my previous issue, but the health system gets drained so fast I even tried to use prefab and fade script on it
If a lot of firing is taking place this could still slow down if you keep instantiating new bullets as they are fired. You could instantiate a pool of bullets earlier on, that are then used in the code.