I'm having some trouble working with this, it's basically a sword that points toward your mouse position, and when you Left-Click, a Trigger Collider is activated and then deactivated, but I can't get it to work.
Here is my code :
void Attack()
{
//Activates the Sword Collider
polygonCollider2D.enabled = true;
//Debug Line
Debug.Log("Collider Active");
StartCoroutine(Wait(0.1f));
polygonCollider2D.enabled = false;
}
IEnumerator Wait(float seconds)
{
yield return new WaitForSeconds(seconds);
}
I did it this way hoping that the Wait
method would give the game enough time to react to an active collider, and using some Debug.Log()
. I know that the collider actually activates, but it does not react to other colliders.
I keep wondering if this is the proper way of working with this. If it's not, do let me know.