I’ll add some context:
Enemies and the Player Character have collider (triggered) for their hitboxes and weapons with their own collider (not triggered).
With this, I’m creating the effect of actually hitting the targets instead of using range (the movement is by using a gamepad, not point and click). I have 2 methods called by an Animator Event (Enable and Disable Weapons) to match the “hitting” part of the animation (I don’t want a sword to be able to hit the target when it is barely starting to swing)
If the attack gets interrupted before disabling the weapon, a state machine calls the method to Disable the weapon, because if an enemy hits the player while the player is attacking another target, the player’s attack is canceled.
So, when the player (or enemy) swings his weapon, during the attack animation (calling 2 animator events, calling Enable and Disable Weapon) if the weapon is instantiated instead of being part of the player’s prefab, it freezes for some frames.
The Methods are very simple, they change the layer of the weapon (to avoid the player and enemy colliding with themselves) and enable/disable the collider.
This happens at one specific frame when the player/enemy attacks.
public void EnableWeaponDamage()
{
m_collider.enabled = true;
if (thisIsThePlayer) m_Weapon.layer = playerWeaponLayer;
else m_Weapon.layer = enemyWeaponLayer;
}
public void DisableWeaponDamage()
{
m_collider.enabled = false;
m_Weapon.layer = propsLayer; //Weapon goes to the Props layers
}```